Registry / database / python-redis-rate-limit

python-redis-rate-limit

JSON →
library0.0.10pypypi✓ verified 82d ago

A Python rate limiter based on Redis using a sliding window algorithm. It provides a decorator and context manager to limit the rate of function calls or code blocks. Version 0.0.10 is the latest release, with no recent updates; the package appears to be in maintenance mode.

pip install python-redis-rate-limit
INSTALL
IMPORT
SIG · PYTHON-REDIS-RATE-
P
python-redis-rate-limit
databasepythonv0.0.10
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RateLimiter
from redis_rate_limit import RateLimiter
from rate_limit import rate_limit
RateLimit
from redis_rate_limit import RateLimit
TooManyRequests
from redis_rate_limit import TooManyRequests

Basic usage of the rate_limit decorator, limiting to 10 calls per 60 seconds.

import redis from rate_limit import rate_limit r = redis.Redis(host='localhost', port=6379, db=0) @rate_limit(r, max_calls=10, period=60) def my_function(): print('Function called') for _ in range(12): my_function()
Debug
Known issues
gotchaThe rate_limit decorator uses a sliding window, but requires a Redis instance. If Redis is down, the decorator will raise redis.exceptions.ConnectionError. The library does not handle connection failures gracefully.
fix
Wrap decorated calls in try-except or implement a fallback mechanism (e.g., check Redis availability before decorating).
affects: all
deprecatedIn v0.0.9, deprecated distutils.version was removed. This may affect users relying on Python 2.7 support (which was also removed). The library now requires Python 3.
fix
Upgrade to Python 3 and use v0.0.9 or later.
affects: >=0.0.9
gotchaThe package uses a global redis client reference; if multiple decorators or context managers are used with different Redis instances, the wrong instance may be used due to how the library stores the connection internally.
fix
Instantiate a new rate limiter object locally or ensure only one Redis instance is used. Check the source code for details.
affects: all
Upgrade
Version history
0.0.10latest on PyPI · released Oct 23, 2024
Audit
Dependencies
redisrequiredRequired for Redis connection
Agent activity
17 hits · last 30 days
node
14
OpenAI (training)
1
Resources
python-redis-rate-limit — pip install python-redis-rate-limit · libregistry