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 rate limiting system for a multi-tenant API service that enforces per-tenant rate limits with different tiers.
The system should support three tenant tiers with different rate limits:
Implement a rate limiter that:
@generates
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
"""
passProvides rate limiting functionality with bucket-based algorithms.