This packages introduces a function decorator preventing a functions from being called more often than allowed. This should prevent API providers from banning your applications by conforming to their rate limits.
It's similar to ratelimit with the following differences:
- also handles async functions
- accepts multiple limits (burst mode)
- allows applying rate limit to many functions
- allows assigning a cost
- sleep_and_retry utility is a function and accepts a limit of retries (1 by default)
Thanks to anyio it works under asyncio and trio event loops.
Usage
from datetime import timedelta
from ratelimit_anyio import *
limiter = RateLimiter((
RateLimit(timedelta(seconds=10), 10),
RateLimit(timedelta(minutes=10), 100),
))
@limiter(cost=1)
async def function():
# Simulate a remote call
import asyncio
await asyncio.sleep(3)
This function can be called up to 100 times within 10 minutes, and 10 times within any 10 seconds (burst mode). You can also declare functions cost (1 by default) which is useful when applying to more than one function, and they use the quota by different values
Metadata
Release files for ratelimit-anyio 0.2.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 |
|---|---|---|---|---|
| ratelimit_anyio-0.2.0.tar.gz | 6.7 kB | Without provenance | Details for ratelimit_anyio-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ratelimit_anyio-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for ratelimit_anyio-0.2.0-py3-none-any.whl |
Total release size: 13.8 kB
Release files / ratelimit_anyio-0.2.0.tar.gz
| Download URL | ratelimit_anyio-0.2.0.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9a8bd8701985b3ed39dfaf7c2798aa65d7bc84b131328ebefb390be4a4695c72
|
|
BLAKE2b-256 checksum How to use checksums |
5414614c38212eaa8330087cf8f01c850a7aa461865ba762b9846ccf741a884b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.12.1 Linux/6.1.0-16-amd64
|
Release files / ratelimit_anyio-0.2.0-py3-none-any.whl
| Download URL | ratelimit_anyio-0.2.0-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7370e950c90db6c184e54c9fa83007757f5c9da47774bdf0e244aceb6d5d9fb0
|
|
BLAKE2b-256 checksum How to use checksums |
fb9d58b90d128b980c1e81d175e5e3d69e56cd0a8440367c6a23eb74ccd7c0d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.12.1 Linux/6.1.0-16-amd64
|
Security for ratelimit-anyio 0.2.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.