openfoodfacts_proxy.infrastructure.rate_limiter
source module openfoodfacts_proxy.infrastructure.rate_limiter
Classes
-
SlidingWindowRateLimiter — In-memory sliding window rate limiter tracking requests per IP and bucket.
source class SlidingWindowRateLimiter(rate_limit_settings: RateLimitSettings | None = None)
In-memory sliding window rate limiter tracking requests per IP and bucket.
Methods
-
is_within_limit — Check if the request is within rate limit. Records the request if within limit.
-
get_remaining — Get the number of remaining requests allowed in the current window.
-
cleanup — Remove all expired entries to free memory.
source method SlidingWindowRateLimiter.is_within_limit(ip: str, bucket: str) → bool
Check if the request is within rate limit. Records the request if within limit.
Returns True if the request is allowed (within limit), False if rate limit exceeded.
source method SlidingWindowRateLimiter.get_remaining(ip: str, bucket: str) → int
Get the number of remaining requests allowed in the current window.
source method SlidingWindowRateLimiter.cleanup() → None
Remove all expired entries to free memory.