File size: 517 Bytes
734aed4 ccd9777 734aed4 ccd9777 734aed4 ccd9777 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
from slowapi.util import get_remote_address
from slowapi import Limiter
from fastapi import Request
# Initialize a limiter instance
limiter = Limiter(key_func=get_remote_address)
def check_rate_limit(request: Request):
"""
Function to check if a user has exceeded their rate limit.
This is managed by slowapi's limiter.
"""
if not limiter.is_allowed(request):
raise HTTPException(
status_code=429,
detail="Rate limit exceeded. Please try again later."
)
|