RateLimiter¶
Sliding-window rate limiter for throttling HTTP API calls.
- class scamander.api.rate_limiter.RateLimiter(max_calls: int, period_secs: float = 60.0)¶
Bases:
objectSliding-window rate limiter for HTTP API calls.
Tracks request timestamps within a rolling
period_secswindow.acquire()blocks until a slot is available, keeping throughput at or belowmax_callsperperiod_secs.- Parameters:
max_calls – Maximum number of calls allowed within the window.
period_secs – Window length in seconds. Defaults to
60.
Example:
limiter = RateLimiter(max_calls=300, period_secs=60) for url in urls: limiter.acquire() response = session.get(url)
- acquire()¶
Block until a request slot is available within the current window.