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
Close
Hashes for python-redis-rate-limit-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7e0875d1d0d0e6930bf23e936de788783d43ee9e28cfa5e79c706e4b8f87c1a |
|
MD5 | 7e61be0c1038977f8ba5b1b5d34faa59 |
|
BLAKE2b-256 | c835d6104a29f92909657b379976841634ec87bba65ad5f4eaeaef45c03ca3df |