or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pyrate-limiter@3.9.x
tile.json

tessl/pypi-pyrate-limiter

tessl install tessl/pypi-pyrate-limiter@3.9.0

Python 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%

task.mdevals/scenario-2/

API Request Tracker

Build a simple API request tracking system that monitors and controls the rate of API calls to ensure compliance with rate limits.

Overview

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.

Capabilities

Request rate limiting

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:

  • "client_1": 5 requests per minute
  • "client_2": 3 requests per second
  • "client_3": 2 requests per second

Test cases:

  • Returns True when first request from "client_1" is made (within 5/minute limit) @test
  • Returns False in non-blocking mode when "client_2" makes 4th request within same second (exceeds 3/second limit) @test
  • Blocks and returns True when "client_3" makes 3rd request in blocking mode, waiting until second elapses @test

API

def 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

Implementation

@generates

Dependencies { .dependencies }

Rate limiting { .dependency }

Provides rate limiting capabilities for controlling request rates with configurable time windows.

@satisfied-by