
Security News
Open Source Maintainers Demand Ability to Block Copilot-Generated Issues and PRs
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
python-redis-rate-limit
Advanced tools
.. image:: https://github.com/EvoluxBR/python-redis-rate-limit/actions/workflows/python-package.yml/badge.svg :target: https://github.com/EvoluxBR/python-redis-rate-limit/actions/workflows/python-package.yml
.. image:: https://img.shields.io/pypi/v/python-redis-rate-limit.svg :target: https://pypi.python.org/pypi/python-redis-rate-limit
.. image:: https://img.shields.io/pypi/dm/python-redis-rate-limit.svg :target: https://pypi.python.org/pypi/python-redis-rate-limit
This lib offers an abstraction of a Rate Limit algorithm implemented on top of Redis >= 2.6.0.
Supported Python Versions: 2.7, 3.6+
Example: 10 requests per second
.. code-block:: python
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: using as a decorator
.. code-block:: python
from redis_rate_limit import RateLimit, TooManyRequests
@RateLimit(resource='users_list', client='192.168.0.10', max_requests=10)
def list_users():
return '200 OK'
try:
return list_users()
except TooManyRequests:
return '429 Too Many Requests'
Example: 600 requests per minute
.. code-block:: python
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
.. code-block:: python
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'
Example: you can also setup a factory to use it later
.. code-block:: python
from redis_rate_limit import RateLimiter, TooManyRequests
limiter = RateLimiter(resource='users_list', max_requests=100, expire=3600)
try:
with limiter.limit(client='192.168.0.10'):
return '200 OK'
except TooManyRequests:
return '429 Too Many Requests'
Example: you can also pass an optional Redis Pool
.. code-block:: python
import redis
from redis_rate_limit import RateLimit, TooManyRequests
redis_pool = redis.ConnectionPool(host='127.0.0.1', port=6379, db=0)
try:
with RateLimit(resource='users_list', client='192.168.0.10', max_requests=10, redis_pool=redis_pool):
return '200 OK'
except TooManyRequests:
return '429 Too Many Requests'
FAQs
Python Rate Limiter based on Redis.
We found that python-redis-rate-limit demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
Research
Security News
Malicious Koishi plugin silently exfiltrates messages with hex strings to a hardcoded QQ account, exposing secrets in chatbots across platforms.
Research
Security News
Malicious PyPI checkers validate stolen emails against TikTok and Instagram APIs, enabling targeted account attacks and dark web credential sales.