Skip to main content

Rate limiter for Async IO

Project description

asynciolimiter

A simple 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

  • 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


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

asynciolimiter-1.0.0a4-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file asynciolimiter-1.0.0a4-py3-none-any.whl.

File metadata

File hashes

Hashes for asynciolimiter-1.0.0a4-py3-none-any.whl
Algorithm Hash digest
SHA256 ada380d99f22394b0d0ad26ebda2c0e8c953e8ae8bc415d1686c5da24a19c14c
MD5 e1672a06872d83b442d4835717b99aa4
BLAKE2b-256 16e5c20bbf02759451bbed413da678d0463d57962818206d23acdb4cd4e5632e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page