Enable rate limiting
michaelfeil opened this issue ยท 3 comments
michaelfeil commented
Have you considered adding a rate limiter? I have made good experiences with:
https://pypi.org/project/fastapi-limiter/
In this case,
from fastapi_limiter import FastAPILimiter
from fastapi_limiter.depends import RateLimiter
@app.on_event("startup")
async def startup():
redis = redis.from_url("redis://localhost", encoding="utf-8", decode_responses=True)
await FastAPILimiter.init(redis)
and
app = FastAPI(dependencies=[RateLimiter(times=2, seconds=5))])
. If you want, might also be added as optional, or if redis is offline:
# for forward compatability:
if os.environ.get("RATE_LIMIT", False):
...
KenyonY commented
It looks great. fastapi-limiter is a nice library, but it requires Redis
. Perhaps https://github.com/laurentS/slowapi is also a good alternative?
michaelfeil commented
Also a great choice, seems to have redis support and support for local filesystem.
KenyonY commented
๐๐ In version v0.5.0, the rate limit functionality has been implemented. Thank you for your suggestion.