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

Multi-Tenant API Rate Limiter

Build a rate limiting system for a multi-tenant API service that enforces per-tenant rate limits with different tiers.

Requirements

The system should support three tenant tiers with different rate limits:

  • Basic tier: 10 requests per minute
  • Premium tier: 50 requests per minute
  • Enterprise tier: 200 requests per minute

Implement a rate limiter that:

  • Routes requests to separate buckets based on tenant ID
  • Dynamically creates buckets for new tenants as needed
  • Uses in-memory storage for simplicity
  • Blocks when rate limits are exceeded

Test Cases

  • A basic tenant can make 10 requests within a minute successfully @test
  • A basic tenant making 11 requests within a minute is blocked on the 11th request @test
  • A premium tenant can make 50 requests within a minute successfully @test
  • Multiple tenants with the same tier have independent rate limits @test

Implementation

@generates

API

class TenantTier:
    """Enum for tenant tiers"""
    BASIC = "basic"
    PREMIUM = "premium"
    ENTERPRISE = "enterprise"

class TenantRateLimiterFactory:
    """Factory that routes rate limiting by tenant ID and tier"""

    def __init__(self):
        """Initialize the factory"""
        pass

    def register_tenant(self, tenant_id: str, tier: str) -> None:
        """
        Register a tenant with a specific tier.

        Args:
            tenant_id: Unique identifier for the tenant
            tier: Tier level (basic, premium, or enterprise)
        """
        pass

    def acquire(self, tenant_id: str) -> bool:
        """
        Try to acquire a rate limit permit for a tenant.

        Args:
            tenant_id: The tenant requesting access

        Returns:
            True if request is allowed, blocks if rate limit exceeded
        """
        pass

Dependencies { .dependencies }

pyrate-limiter { .dependency }

Provides rate limiting functionality with bucket-based algorithms.