async-redis-rate-limiters
Rock solid async python (3.13+) generic distributed rate limiters (concurrency and time) backed by Redis.
Features
- ✅ Support very high concurrency (>100K), keep a reasonable number of connections to Redis (default: 300)
- ✅ Rock solid with Redis/Network failures (multiple attempts, exponential backoff, etc.)
- you can restart the Redis server during the execution without any exception or losing any semaphore! (of course, if persistence is setup in the redis instance)
- ✅ Very high performances with almost no polling at all
- ✅ Memory backend (for testing)
Non-features
- ❌ No time based rate limiters (yet)
- ❌ No blocking support, only async Python
Installation
pip install async-redis-rate-limiters
(or same with your favorite package manager)
Usage
import asyncio
from async_redis_rate_limiters import DistributedSemaphoreManager
async def worker(manager: DistributedSemaphoreManager):
# Limit the concurrency to 10 concurrent tasks for the key "test"
async with manager.get_semaphore("test", 10):
# concurrency limit enforced here
pass
async def main():
manager = DistributedSemaphoreManager(
redis_url="redis://localhost:6379",
redis_max_connections=100,
redis_ttl=3600, # semaphore max duration (seconds)
)
tasks = [asyncio.create_task(worker(manager)) for _ in range(1000)]
await asyncio.gather(*tasks)
if __name__ == "__main__":
asyncio.run(main())
What about if you want to use the memory backend?
WARNING: the memory backend is just a wrapper on a classic asyncio.Semaphore, it is not "distributed" at all!
manager = DistributedSemaphoreManager(
backend = "memory"
)
# and use it classically
Dev
- Lint the code:
make lint
- Run the tests:
make test
note: you need a redis instance listening to localhost:6379
Metadata
Release files for async-redis-rate-limiters 0.1.7
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_redis_rate_limiters-0.1.7.tar.gz | 8.7 kB | Without provenance | Details for async_redis_rate_limiters-0.1.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| async_redis_rate_limiters-0.1.7-py3-none-any.whl | Python 3 | none | any | Details for async_redis_rate_limiters-0.1.7-py3-none-any.whl |
Total release size: 18.0 kB
Release files / async_redis_rate_limiters-0.1.7.tar.gz
| Download URL | async_redis_rate_limiters-0.1.7.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
38601047a2a2b9358d92fcba2863e56969b75e35a17f8955ce6550368d3f6f4b
|
|
BLAKE2b-256 checksum How to use checksums |
65ae59951aa5425f138647c68715979a9aba46d02366e75c8bdeb6330a20b14f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.5
|
Release files / async_redis_rate_limiters-0.1.7-py3-none-any.whl
| Download URL | async_redis_rate_limiters-0.1.7-py3-none-any.whl |
|---|---|
| Size | 9.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e7fec98314d63987d9ad2a0d837c748fe2b779542ed9b4b8743c697f2f74d099
|
|
BLAKE2b-256 checksum How to use checksums |
331e92e2dd89047bb71b2ddca888b2c317e4177a6a52687423d5139f703971df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.5
|
Security for async-redis-rate-limiters 0.1.7
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.