High-performance async rate limiter for FastAPI with Redis or native in-memory backend
Project description
fastapi-easylimit
Simple async rate-limiting middleware for FastAPI with Redis or in-memory caching.
Simple design
- Async rate limiting
- Redis or in-memory cache
Installation
pip install fastapi-easylimit
Usage
from fastapi import FastAPI
from fastapi_easylimiter import AsyncRedisBackend, InMemoryBackend
import redis.asyncio as redis_async
app = FastAPI()
REDIS_URL = "redis://localhost:6379/0"
# Redis client
redis_client = redis_async.from_url(REDIS_URL, decode_responses=True)
backend = AsyncRedisBackend(redis_client)
# Or for 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
)
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.3.tar.gz.
File metadata
- Download URL: fastapi_easylimiter-0.1.3.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af4cffbe5d203ade8605d13f79ea5812e08c6252076bcd5a4c445b2d7ceaa3b4
|
|
| MD5 |
f4d578990157bb12e7ab719555024c8e
|
|
| BLAKE2b-256 |
2fff0d248f1ffdc8c72281dcc09dcb3a098319aa890ade317a1523ba13d7eb49
|
File details
Details for the file fastapi_easylimiter-0.1.3-py3-none-any.whl.
File metadata
- Download URL: fastapi_easylimiter-0.1.3-py3-none-any.whl
- Upload date:
- Size: 5.4 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 |
c4b14679465c4196f647822b7ffa6d713d1ebd810a04553d3230d236c7712e80
|
|
| MD5 |
b85479492957db585d52ff9bf46075a6
|
|
| BLAKE2b-256 |
85a078025c7c0fc6d1260c6a5a667a48bd13b45aa3cc35e6817f5ffb9d87ae35
|