-
First Check
Commit to Help
Example Code@app.get("/", dependencies=[Depends(RateLimiter(times=2, seconds=5))])
async def index():
return {"msg": "Hello World"}DescriptionThere is no official way to add ratelimit in path operation functions , it would be good if we could limit requests to a specific rate , for example: a client can only request to "/" path 3 times in 60 seconds. Wanted Solutioni would like a dependency class to handle ratelimits , Both for HTTP And WEBSOCKET Requests Wanted Code@app.get("/", dependencies=[Depends(RateLimiter(times=2, seconds=5))])
async def index():
return {"msg": "Hello World"}AlternativesNo response Operating SystemLinux Operating System DetailsNo response FastAPI Version0.70.0 Python Version3.9.0 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
|
I recently saw two projects solving this problem: |
Beta Was this translation helpful? Give feedback.
-
NOTE: Im aware of libraries made for handling this , but they are not trustable and useful enough. which one did you use and which one was better ? |
Beta Was this translation helpful? Give feedback.
-
What isn't trustable about them? |
Beta Was this translation helpful? Give feedback.
-
You managed to find a solution which support websockets |
Beta Was this translation helpful? Give feedback.
-
|
I think this features should be built into FastAPI. |
Beta Was this translation helpful? Give feedback.
-
Dude, did you go through the documentation of fastapi-limiter? 'cause it does support websocket. |
Beta Was this translation helpful? Give feedback.

What isn't trustable about them?
They're both literally open-source. You can go ahead and read the code line-by-line if you wanted to to make sure they aren't doing anything nefarious. Which I doubt they are.