Redis-based rate-limiting for FastAPI
Project description
FastAPI Ratelimiter
[]
Documentation: https://fastapi-ratelimit.readthedocs.io/en/latest/
Quick start:
import asyncio
import aioredis
import uvicorn
from fastapi import FastAPI, Depends
from starlette.responses import JSONResponse
from fastapi_ratelimiter import RateLimited, RedisDependencyMarker
from fastapi_ratelimiter.strategies import BucketingRateLimitStrategy
app = FastAPI()
redis = aioredis.from_url("redis://localhost", decode_responses=True, encoding="utf-8")
@app.get(
"/some_expensive_call", response_class=JSONResponse,
dependencies=[
Depends(RateLimited(BucketingRateLimitStrategy(rate="10/60s")))
]
)
async def handle_test_endpoint():
await asyncio.sleep(5)
return {"hello": "world"}
app.dependency_overrides[RedisDependencyMarker] = lambda: redis
uvicorn.run(app)
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
fastapi-ratelimiter-0.0.1.tar.gz
(17.0 kB
view hashes)
Built Distribution
Close
Hashes for fastapi-ratelimiter-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f13ef0e43da6af9e2c9fece425db2097afeb4ddabdf597ace7c0b18c94449838 |
|
MD5 | 55ef75e644f2b712cfa25787992456c0 |
|
BLAKE2b-256 | 86eb599c7780dd64d387b11e3605b54570eac067bb24d377ac8236edbe171233 |
Close
Hashes for fastapi_ratelimiter-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7586999903cfdefff082376f7fdb16f379bffd34b3586ede07bbeddbaa37f4ce |
|
MD5 | 5a47b9d8a9a3970c78de7fa2b142f5f1 |
|
BLAKE2b-256 | 8544a098a0c4d73839bd8134bafcfc35ceb62861e9e314a4db0dbfd3a6dd2f50 |