Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable rate limiting #53

Closed
michaelfeil opened this issue Jul 27, 2023 · 3 comments
Closed

Enable rate limiting #53

michaelfeil opened this issue Jul 27, 2023 · 3 comments

Comments

@michaelfeil
Copy link

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
Copy link
Owner

KenyonY commented Jul 31, 2023

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
Copy link
Author

Also a great choice, seems to have redis support and support for local filesystem.

@KenyonY
Copy link
Owner

KenyonY commented Aug 17, 2023

🎉🎉 In version v0.5.0, the rate limit functionality has been implemented. Thank you for your suggestion.

@KenyonY KenyonY closed this as completed Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants