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%
Build a simple API request tracking system that monitors and controls the rate of API calls to ensure compliance with rate limits.
Create a request tracker that limits the number of API requests within specified time windows. The system should support both blocking mode (wait until a request can proceed) and non-blocking mode (immediately return whether a request is allowed). The tracker should enforce rate limits and provide clear feedback about request acceptance.
Implement a function can_make_request(client_id, blocking=True) that checks if a request from a specific client can proceed. Each client has its own rate limit configured as follows:
Test cases:
True when first request from "client_1" is made (within 5/minute limit) @testFalse in non-blocking mode when "client_2" makes 4th request within same second (exceeds 3/second limit) @testTrue when "client_3" makes 3rd request in blocking mode, waiting until second elapses @testdef can_make_request(client_id: str, blocking: bool = True) -> bool:
"""
Check if a request from the specified client can proceed.
Args:
client_id: Unique identifier for the client making the request
blocking: If True, wait until request can proceed; if False, return immediately
Returns:
True if request is allowed, False otherwise (only in non-blocking mode)
"""
pass@generates
Provides rate limiting capabilities for controlling request rates with configurable time windows.
@satisfied-by