Async Throttle
Multipurpose concurrency primitive for asyncio coroutines.
Features
This throttle is configured with two related, but different parameters:
Throttle(capacity: float, concurrency: int = 0, period: float = 1.0)
capacity - Sets the rate limit for requests, as capacity per period seconds.
concurrency - The number of jobs that can be executing at a given time.
Usually, servers will set policies on both of these dimensions, and will suspend clients that violate either of them.
Throttle#pause(td: int)
The pause method will lock the throttle for the given number of seconds.
For example, if an API bans your client from accessing resources due to violating their rate-limit, you can tell your code to sleep for a period of time and try again later.
Usage
The throttle can be a drop-in replacement for another primitive like asyncio.Semaphore.
In fact, it's really just an asyncio.Semaphore (which handles the concurrency limit) mixed with a token bucket to provide rate limiting.
throttle = Throttle(10, 2) # Two concurrent coros limited to 10qps (total).
# Perform one task when the budget allows
async with throttle:
# Do some (async) thing
# For tasks that should consume more of the budget, you can call the throttle:
async with throttle(5):
# Do some more expensive thing, equivalent to 5 requests
Like other asyncio primitives, Throttle is not thread-safe.
Metadata
Release files for async-throttle 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| async_throttle-1.0.0.tar.gz | 4.8 kB | Without provenance | Details for async_throttle-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| async_throttle-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for async_throttle-1.0.0-py3-none-any.whl |
Total release size: 11.1 kB
Release files / async_throttle-1.0.0.tar.gz
| Download URL | async_throttle-1.0.0.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9bb35cd57a55164c4f8c54bc15c0161b0068f89b4785caf468ab298c96ed1989
|
|
BLAKE2b-256 checksum How to use checksums |
05cf7056117cb35d4f6040464e669b763103a6419d65c04af487f131b4ba79b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.11.3 Darwin/22.5.0
|
Release files / async_throttle-1.0.0-py3-none-any.whl
| Download URL | async_throttle-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
db0df33190357548383e46b4e8189a81bb3e0bc609c9952f3ed3fa70dba1ce64
|
|
BLAKE2b-256 checksum How to use checksums |
c9125f26c43a09e194240927b00da3e2bccb24eea3bb4e3e0c3f25ce552b274f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.11.3 Darwin/22.5.0
|
Security for async-throttle 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.