bharel / asynciolimiter

A simple yet efficient Python AsyncIO rate limiter.
MIT License
17 stars 2 forks source link

asynciolimiter

A simple yet efficient Python AsyncIO rate limiter.

GitHub branch checks state PyPI PyPI - Python Version codecov

Installation

pip install asynciolimiter

Sample Usage

# Limit to 10 requests per 5 second (equiv to 2 requests per second)
>>> limiter = asynciolimiter.Limiter(10/5)
>>> async def main():
...     await limiter.wait() # Wait for a slot to be available.
...     pass # do stuff

>>> limiter = Limiter(1/3)
>>> async def request():
...     await limiter.wait()
...     print("Request")  # Do stuff
...
>>> async def main():
...     # Schedule 1 request every 3 seconds.
...     await asyncio.gather(*(request() for _ in range(10)))

Available Limiter flavors

Documentation

Full documentation available on Read the Docs.

License

Licensed under the MIT License.

Contribution

See contributing.md.