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.2.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

asynciolimiter-1.2.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file asynciolimiter-1.2.0.tar.gz.

File metadata

  • Download URL: asynciolimiter-1.2.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for asynciolimiter-1.2.0.tar.gz
Algorithm Hash digest
SHA256 ac1a237c3dbd3c33041c9f9fc1a687c8e6b5268af69da84399967173a344b265
MD5 6720a87f7a5dcfdfd2e4d15a444f00c4
BLAKE2b-256 5b95e419550994947b564302c6d6641462d1c154e535df7e6a4bedc2801ec6d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for asynciolimiter-1.2.0.tar.gz:

Publisher: release.yml on bharel/asynciolimiter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file asynciolimiter-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: asynciolimiter-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for asynciolimiter-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0d255de14459f961c8baee7f91e114a6ffb9ce5615e9b19c0049e8ae7e2ac84c
MD5 e991a03acb226ad4ca8fba3dce98ef67
BLAKE2b-256 ee912fd273f5c9d041e987cb03f487722355527c412870ece6f803fe2799f2a7

See more details on using hashes here.

Provenance

The following attestation bundles were made for asynciolimiter-1.2.0-py3-none-any.whl:

Publisher: release.yml on bharel/asynciolimiter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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