Dynamic rate limit based on user type
See original GitHub issueI need a way to dynamically set the rate limit based on the user type.
For example, I want to limit users without access token & have unlimited access to users with the access token.
What I am currently using:
limiter = Limiter(key_func=identify_my_user_func)
app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)
def identify_my_user_func(request: Request):
if 'access_token' not in request.query_params:
return request.client.host
return "REGISTERED_USER"
@limiter.limit("2/minute")
def some_request(request: Request)):
return data
I am trying to find a way to conditionally limit 2/minute. Basically I want to increase the limit based on the user type.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
learn hapi — Dynamic Rate Limits (Part 3 of 7) - Future Studio
Imagine dynamic rate limits as limits that vary between users. For example, varying limits between users occur on SaaS subscriptions where you ...
Read more >Rate-limiting strategies and techniques - Google Cloud
When the capacity of a service is shared among many users or consumers, it can apply rate limiting per user to provide fair...
Read more >Configure Rate Limiting per User
This guide provides instructions on how to configure rate limiting per user based on the user identification in the F5® Distributed Cloud Console...
Read more >Introducing Advanced Rate Limiting - The Cloudflare Blog
Advance Rate Limiting allows counting requests based on virtually any characteristics of the HTTP request, regardless of its source IP.
Read more >Dynamic Rate Limiting - YouTube
A default rate limit policy is a great way to protect your API, but sometimes you need more control.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was able to solve this by the link you had shared, below is the way if someone needs it:
Cheers!! @laurentS
Hi @sdklab007, you should be able to use a callable to pick the limit, like:
and if you want some users to be exempted from the limit, you should also be able to do:
I hope this helps!