asyncio-redis-rate-limit
Rate limiter for async functions using Redis as a backend.
Features
- Small and simple
- Can be used as a decorator or as a context manager
- Can be used for both clients and servers
- Works with
asyncio - Works with any amount of processes
- Works with both
redis.asyncio.client.Redisandaioredis - Free of race-conditions (hopefully!)
- Supports
redissince7.0 - Fully typed with annotations and checked with mypy, PEP561 compatible
Installation
pip install asyncio-redis-rate-limit
Extras available:
pip install asyncio-redis-rate-limit[redis]pip install asyncio-redis-rate-limit[aioredis](for python versions<3.11)
Example
As a decorator:
>>> from asyncio_redis_rate_limit import rate_limit, RateSpec
>>> from redis.asyncio import Redis as AsyncRedis # pip install redis
>>> redis = AsyncRedis.from_url('redis://localhost:6379')
>>> @rate_limit(
... rate_spec=RateSpec(requests=1200, seconds=60),
... backend=redis,
... )
... async def request() -> ...:
... ... # Do something useful! Call this function as usual.
Or as a context manager:
>>> from asyncio_redis_rate_limit import RateLimiter, RateSpec
>>> from redis.asyncio import Redis as AsyncRedis # pip install redis
>>> redis = AsyncRedis.from_url('redis://localhost:6379')
>>> async def request() -> ...:
... async with RateLimiter(
... unique_key='api-name.com',
... backend=redis,
... rate_spec=RateSpec(requests=5, seconds=1),
... ):
... ... # Do the request itself.
License
Credits
This project was generated with wemake-python-package. Current template version is: 1d63652fbb33ebe2f6d932f511b7f529a4ce2d2a. See what is updated since then.
Release files for asyncio-redis-rate-limit 1.1.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 | |
|---|---|---|---|
| asyncio_redis_rate_limit-1.1.0.tar.gz | 6.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| asyncio_redis_rate_limit-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.5 kB
Release files / asyncio_redis_rate_limit-1.1.0.tar.gz
| Download URL | asyncio_redis_rate_limit-1.1.0.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
12b176456b07b24b2244fee258bd6e35cf9a11d67c199a1826cda9a1299b4229
|
|
BLAKE2b-256 checksum How to use checksums |
76c3994e0fef58df8545a66943139bdeb6636fedfb392a8c890e48b4e8cf45a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.0 CPython/3.11.9 Darwin/24.6.0
|
Release files / asyncio_redis_rate_limit-1.1.0-py3-none-any.whl
| Download URL | asyncio_redis_rate_limit-1.1.0-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e6c5553b603b50073868def1bba898715b5aafbb4dbd1f80b7172115c62aedf1
|
|
BLAKE2b-256 checksum How to use checksums |
5b68c73908b3d482bc286d9611592c533d9bda680076a7a0370b0e8679f29f44
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.0 CPython/3.11.9 Darwin/24.6.0
|