Rate limiter for Async IO
Project description
asynciolimiter
A simple yet efficient Python AsyncIO rate limiter.
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
Limiter
: Limits by requests per second and takes into account CPU heavy tasks or other delays that can occur while the process is sleeping.LeakyBucketLimiter
: Limits by requests per second according to the leaky bucket algorithm. Has a maximum capacity and an initial burst of requests.StrictLimiter
: Limits by requests per second, without taking CPU or other process sleeps into account. There are no bursts and the resulting rate will always be a less than the set limit.
Documentation
Full documentation available on Read the Docs.
License
Licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file asynciolimiter-1.1.0.post0-py3-none-any.whl
.
File metadata
- Download URL: asynciolimiter-1.1.0.post0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf40ad478073fb11069654a7d9e595bfb5e2d454378c436472af5662a122286a |
|
MD5 | 25af627de87bf06c6853c810c380a934 |
|
BLAKE2b-256 | 40458b388e900a2ba770c319e3f9242f4e8fd819531d62548541273559b8fa5f |