Quota Management
Enforce hard limits on resource usage over long periods (e.g., monthly API calls).
Unlike rate limits which handle traffic spikes, quotas handle total consumption over a longer period.
Setting up Quotas
from halt.core.quota import QuotaManager, QuotaPolicy
# 1 Million requests per month
QUOTA_PRO = QuotaPolicy(
name="pro_monthly",
limit=1_000_000,
period=30 * 24 * 3600 # 30 days
)
quota_manager = QuotaManager(store)
Checking Quotas
async def check_usage(user_id: str):
allowed, usage = await quota_manager.check_quota(
user_id,
QUOTA_PRO
)
if not allowed:
raise QuotaExceededError()
# Consume 1 unit
await quota_manager.consume(user_id, QUOTA_PRO, amount=1)