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-6/

Async API Rate Limiter

Build an asynchronous rate-limited API client that enforces request limits and handles concurrent requests properly.

Requirements

You need to implement an async API client that:

  1. Makes HTTP requests to multiple endpoints asynchronously
  2. Enforces a rate limit of 5 requests per second
  3. Properly handles concurrent requests without exceeding the rate limit
  4. Waits appropriately when rate limits are reached rather than failing
  5. Uses non-blocking async/await patterns throughout

Your implementation should include:

  • An async function fetch_user_data(user_id: int) -> dict that simulates fetching user data
  • An async function fetch_posts_data(post_id: int) -> dict that simulates fetching post data
  • An async function process_batch(user_ids: list, post_ids: list) -> dict that fetches all data concurrently while respecting rate limits

The batch processor should:

  • Return a dictionary with keys "users" and "posts" containing lists of fetched data
  • Handle at least 10 concurrent requests (more than the per-second limit)
  • Complete all requests successfully by waiting when necessary

Implementation

@generates

API

async def fetch_user_data(user_id: int) -> dict:
    """Fetch user data with rate limiting applied."""
    pass

async def fetch_posts_data(post_id: int) -> dict:
    """Fetch post data with rate limiting applied."""
    pass

async def process_batch(user_ids: list, post_ids: list) -> dict:
    """Process multiple requests concurrently with rate limiting.

    Returns:
        dict: {"users": [user_data...], "posts": [post_data...]}
    """
    pass

Test Cases

  • Fetching a single user returns a dictionary with user_id @test
  • Fetching a single post returns a dictionary with post_id @test
  • Processing a batch of 8 users and 7 posts returns all 15 items @test
  • The rate limiter prevents more than 5 requests in any 1-second window @test

Dependencies { .dependencies }

pyrate-limiter { .dependency }

Provides rate limiting support with async/await capabilities.