Python Rate Limiter based on Redis.
Project description
This lib offers an abstraction of a Rate Limit algorithm implemented on top of Redis >= 2.6.0.
Example: 10 requests per second
>>> from redis_rate_limit import RateLimit, TooManyRequests
>>> try:
>>> with RateLimit(resource='users_list', client='192.168.0.10', max_requests=10):
>>> return '200 OK'
>>> except TooManyRequests:
>>> return '429 Too Many Requests'
>>>
Example: 600 requests per minute
>>> from redis_rate_limit import RateLimit, TooManyRequests
>>> try:
>>> with RateLimit(resource='users_list', client='192.168.0.10', max_requests=600, expire=60):
>>> return '200 OK'
>>> except TooManyRequests:
>>> return '429 Too Many Requests'
>>>
Example: 100 requests per hour
>>> from redis_rate_limit import RateLimit, TooManyRequests
>>> try:
>>> with RateLimit(resource='users_list', client='192.168.0.10', max_requests=100, expire=3600):
>>> return '200 OK'
>>> except TooManyRequests:
>>> return '429 Too Many Requests'
>>>
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file python-redis-rate-limit-0.0.3.tar.gz
.
File metadata
- Download URL: python-redis-rate-limit-0.0.3.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 247d34e9b556252dabb9f0720ea863f6c276cb02c2fa23af87e94d13049427c5 |
|
MD5 | f755d750d0c2287ed171c20200877c52 |
|
BLAKE2b-256 | 513de00643cb36f286d40567eb758009540014dce452c7c12af35a363ca265b4 |