Documentation
Installation
pip install meow-redis-ratelimiter
Requires Python 3.7+. If using Redis, make sure you have it installed and running.
Basic Usage (In-Memory Store)
from redis-rate_limiter import RateLimiter
limiter = RateLimiter(max_requests=5, period=60)
@limiter
def my_function(req=None):
return "Allowed!"
# Example
print(my_function()) # Allowed
This version keeps counters in memory. Works for single-process apps (e.g., local dev, small deployments).
Usage with Redis (Distributed Store)
import redis
from redis-rate_limiter import RateLimiter
redis_client = redis.StrictRedis.from_url("redis://localhost:6379/0")
limiter = RateLimiter(
max_requests=5,
period=60,
redis_client=redis_client
)
@limiter
def my_function(req=None):
return "Allowed!"
Use this for production, since Redis synchronizes counters across workers/servers.
Framework Integration
Flask
from flask import Flask, request, jsonify
import redis
from redis-rate_limiter import RateLimiter
app = Flask(__name__)
redis_client = redis.StrictRedis.from_url("redis://localhost:6379/0")
limiter = RateLimiter(
max_requests=5,
period=10,
redis_client=redis_client,
identifier_func=lambda req: req.remote_addr,
error_handler=lambda: (jsonify({"error": "Too Many Requests"}), 429)
)
@app.route("/api/data")
@limiter
def data(req=None):
return {"message": "Success"}
Django
from django.http import JsonResponse
from redis-rate_limiter import RateLimiter
limiter = RateLimiter(
max_requests=5,
period=10,
identifier_func=lambda req: req.META.get("REMOTE_ADDR"),
error_handler=lambda: JsonResponse({"error": "Too Many Requests"}, status=429)
)
@limiter
def my_view(request):
return JsonResponse({"message": "Success"})
FastAPI
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
import redis
from redis-rate_limiter import RateLimiter
app = FastAPI()
redis_client = redis.StrictRedis.from_url("redis://localhost:6379/0")
limiter = RateLimiter(
max_requests=5,
period=10,
redis_client=redis_client,
identifier_func=lambda req: req.client.host,
error_handler=lambda: JSONResponse({"error": "Too Many Requests"}, status_code=429)
)
@app.get("/api/data")
@limiter
async def data(request: Request):
return {"message": "Success"}
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
max_requests |
int |
5 |
Max requests allowed in period |
period |
int |
60 |
Time window in seconds |
redis_client |
redis.Redis or None |
None |
Redis client for distributed limit |
identifier_func |
Callable |
lambda req: "global" |
Extracts a unique identifier (IP, user_id, API key) |
error_handler |
Callable |
returns (msg, 429) |
Handles blocked requests (custom error response) |
How It Works
-
Keeps a sliding window of request timestamps.
-
On each request:
- Expired timestamps are removed.
- If count ≥
max_requests, request is blocked. - Otherwise, request is allowed.
-
With Redis, counters are shared across all workers.
Example with API Key Throttling
limiter = RateLimiter(
max_requests=100,
period=60,
identifier_func=lambda req: req.headers.get("X-API-Key", "anonymous"),
error_handler=lambda: {"error": "Too Many Requests"}, 429
)
Roadmap
- Async support for asyncio/Starlette
- Token bucket mode
- Middleware for direct integration (Flask, Django, FastAPI)
Metadata
Release files for meow-redis-ratelimiter 0.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 | Provenance | |
|---|---|---|---|---|
| meow_redis_ratelimiter-0.1.0.tar.gz | 3.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| meow_redis_ratelimiter-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.4 kB
Release files / meow_redis_ratelimiter-0.1.0.tar.gz
| Download URL | meow_redis_ratelimiter-0.1.0.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dd1dae668d628b41990993626b291039d61d3eac30e0af8a0771bd501a1a3110
|
|
BLAKE2b-256 checksum How to use checksums |
169e8b5f39466fb64ec5796aa27474cba9b1603c54145256985c16b8fcd0fcf0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / meow_redis_ratelimiter-0.1.0-py3-none-any.whl
| Download URL | meow_redis_ratelimiter-0.1.0-py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e47a40e235ddff7c9402530e9fdc26b1953c8f1528276372a7ff9d995fee84b7
|
|
BLAKE2b-256 checksum How to use checksums |
b6b0ae2c28cd1d64f02d5e4f506bde6b7485b850175967e0c99c00065736df9d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for meow-redis-ratelimiter 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.