Skip to main content

Rate limiter for Async IO

Project description

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

  • 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.

Contribution

See contributing.md.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asynciolimiter-1.1.0.post3.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

asynciolimiter-1.1.0.post3-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file asynciolimiter-1.1.0.post3.tar.gz.

File metadata

  • Download URL: asynciolimiter-1.1.0.post3.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for asynciolimiter-1.1.0.post3.tar.gz
Algorithm Hash digest
SHA256 0ce279695126350b38fdb661f6d5976722bf367557156526b93f27614434977d
MD5 96d8dea683307987e8470a69d502e94d
BLAKE2b-256 4f65e7ba4fa38a389fcfecff7b05d19a5dfd82324488ab7dbb821f1f6792a5b2

See more details on using hashes here.

File details

Details for the file asynciolimiter-1.1.0.post3-py3-none-any.whl.

File metadata

File hashes

Hashes for asynciolimiter-1.1.0.post3-py3-none-any.whl
Algorithm Hash digest
SHA256 101b3b8c95f7fa6312f33df96cc773bc7ce46f53f5044b97b832cc1ec9f24688
MD5 6b7c377273d3b70d80cf5d6a485f367a
BLAKE2b-256 05f7c2174deba155e53056f4be8222ee757572abcf80910f713d3048ceb3cf79

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