ammarsys / pyaww

An API wrapper around the PythonAnywhere's API.
https://pyaww-docs.vercel.app/
MIT License
7 stars 2 forks source link

Implement a rate limiting system #2

Open ammarsys opened 2 years ago

ammarsys commented 2 years ago

Implement a rate-limiting system under the pyaww/utils/ directory, specifically pyaww/utils/ratelimit.py.

The rate-limiting algorithm could be a token bucket; or even better a leaky bucket. It should be usable as a decorator and/or with the async for ... syntax. Function, where this would be used, would be the pyaww.User.request method, its first argument is always the URL.

The rate limits are 40/min per every endpoint, the exception being consoles whereas it is 120/min. Timeouts last a minute to my knowledge.

The concurrency in this module is utilizing asyncio. Make sure it's safe from race conditions by using asyncio.Lock() (note, it is already defined in the __init__ of the pyaww.User, to get an idea on how to access it, look at the pyaww/utils/cache.py.)

For anyone looking to contribute, please open PRs for the dev branch which is the new version in work. It will be merged with the main branch after all planned features get implemented.

Please see the contributing manual.

MatiCG commented 2 years ago

Hi, I'm down to take a look at this! I'll give it a try tonight and keep you updated.

ammarsys commented 2 years ago

PRs should be made in the main branch instead of dev.