Is there a way to exempt certain domains from rate limiting using the slowapi extension for Python FastAPI? I want the frontend (my_domain.com) to be exempt from rate-limiting, but any other requests should be rate limited. For example, I am looking for something like this:
def my_key_func(request):
"""Set up a key function that exempts my_domain.com"""
if "my_domain.com" in request.client.host:
# Exempt from limiting
else:
# Do limiting
limiter = Limiter(key_func=my_key_func)
app = FastAPI(lifespan=lifespan)
app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)
@app.get("/limited-route")
@limiter.limit("10/minute")
async def function():
return {"success": 200}
Any ideas? Thanks