tessl install tessl/pypi-pyrate-limiter@3.9.0Python Rate-Limiter using Leaky-Bucket Algorithm for controlling request rates in applications with multiple backend storage options.
Agent Success
Agent success rate when using this tile
81%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.45x
Baseline
Agent success rate without this tile
56%
A simple API request tracking system that enforces rate limits on incoming requests.
Build a request tracker that manages API request limits for different services. The tracker should enforce rate limits and provide feedback about whether requests can be processed or should be delayed.
The tracker should:
@generates
class RequestTracker:
"""
Tracks API requests and enforces rate limits.
Args:
max_requests: Maximum number of requests allowed
time_window_seconds: Time window for the rate limit in seconds
"""
def __init__(self, max_requests: int, time_window_seconds: int):
pass
def process_request(
self,
request_name: str,
blocking: bool = True,
timeout: float | None = None
) -> bool:
"""
Process a request and enforce rate limits.
Args:
request_name: Identifier for the request
blocking: If True, wait for rate limit to allow request.
If False, return immediately if rate limit exceeded.
timeout: Maximum time to wait in blocking mode (seconds).
None means wait indefinitely.
Returns:
True if request can proceed, False if rejected due to rate limit
"""
pass
def close(self):
"""Clean up resources."""
passProvides rate limiting functionality.