add ratelimiting decorator#863
Open
RensDimmendaal wants to merge 5 commits intomainfrom
Open
Conversation
7 tasks
RensDimmendaal
commented
Apr 17, 2026
79dc0bc to
9e00b60
Compare
RensDimmendaal
commented
Apr 23, 2026
Contributor
Author
There was a problem hiding this comment.
@jph00 I wasnt sure how to best handle the default key-ing on IP, because dependent on the reverse proxy, cloudflare and uvicorn setup.
I've made it such that it'll work for local dev and for our common deployment scenario of serving with uvicorn behind Caddy.
I've added this note in the docs, and clarified when client_ip should (not) be used.
But I'm a bit unsure if this is the way to go...maybe it's too opinionated and we shouldnt make client_ip the default?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR depends on: #867
This PR adds a token-bucket rate limiter for FastHTML routes. I figured we needed something like this for the MagicKey PR to avoid abuse of the routes that send emails and I saw it was a common pattern for other web app frameworks. What's different about this implementation is that I've made it easy to re-use the request parameters as a
keyin thelimiter.I didn't add a separate explainer doc page, because the source doc page is quite extensive and builds up nicely. But i can add one if you like.
Example usage:
Types of changes
What types of changes does your code introduce? Put an
xin all the boxes that apply:Checklist
Go over all the following points, and put an
xin all the boxes that apply:Additional Information
The changes to nbs 00 and 01 are due to the latest nbdev-version and not related to this PR.