High-performance async rate limiter for FastAPI with Redis or native in-memory backend
Project description
fastapi-easylimiter
Simple async rate-limiting middleware for FastAPI with Redis or in-memory caching.
Simple design
- Async rate limiting
- Redis or in-memory cache
- Easy rules per URL paths.
- Optional rate limit headers (
X-RateLimit-Limit,X-RateLimit-Remaining,Retry-After)
Installation
pip install fastapi-easylimiter
Usage
from fastapi import FastAPI
from fastapi_easylimiter import AsyncRedisBackend, InMemoryBackend, RateLimiterMiddleware
import redis.asyncio as redis_async
app = FastAPI()
REDIS_URL = "redis://localhost:6379/0"
# Redis backend (recommended for multi-instance deployments)
redis_client = redis_async.from_url(REDIS_URL, decode_responses=True)
backend = AsyncRedisBackend(redis_client)
# Or for single-instance/local development:
# backend = InMemoryBackend()
rules = {
"/api/users": {"limit": 1, "period": 2},
"/api/": {"limit": 60, "period": 60}, # GLOBAL ONES GO LAST
}
app.add_middleware(
RateLimiterMiddleware,
rules=rules,
backend=backend,
backoff_threshold=3,
max_backoff=60
)
Contributing
Contributions and forks are always welcome! Feel free to adapt, improve, or extend this middleware for your own needs. This was purely made out of personal necessity.
Support
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_easylimiter-0.1.6.tar.gz.
File metadata
- Download URL: fastapi_easylimiter-0.1.6.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a93716916faeac8682499ab6d4a95862a12694cf079b0415202b75bc50eb15e
|
|
| MD5 |
b4464fe8f6a83dce20187a261d90a735
|
|
| BLAKE2b-256 |
6c67bba90b77ffbe643b28c10ac04f27cbc0b8350da7dac817e23e4df65ba599
|
File details
Details for the file fastapi_easylimiter-0.1.6-py3-none-any.whl.
File metadata
- Download URL: fastapi_easylimiter-0.1.6-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06eadaf55c2538bf630413ea73f35b576c960194fad923cf291eaf007b5e63f8
|
|
| MD5 |
fa136239dab7e1d5f0471c7c96db1b1a
|
|
| BLAKE2b-256 |
5b438cffd029ed4073bb403de92639cddee4dd32ba7d6424570a8890a5ddbbf2
|