ratelimit
azure_bootstrap.ratelimit
¶
In-process token-bucket rate limiter.
Belt-and-suspenders for L7 rate limiting at ingress (Istio EnvoyFilter is fine; this defends against a sidecar-wedged or local-dev scenario where the ingress filter isn't in the path).
The :func:fastapi_rate_limit helper builds a dependency callable that
returns 429 with an empty body on rejection — detail strings leak budget
state.
Classes:
| Name | Description |
|---|---|
MultiUnitLimiter |
Multi-unit sliding window limiter (pages/records/seconds/chars/calls). |
Functions:
| Name | Description |
|---|---|
fastapi_rate_limit |
FastAPI dependency factory. 429 + empty body on rejection. |
webhook_bucket |
Preset for Microsoft-Graph-style webhooks: 240 burst, 4/s sustained. |
admin_bucket |
Preset for manual-trigger endpoints: 30 burst, 0.5/s sustained. |
MultiUnitLimiter
¶
MultiUnitLimiter(*, limits: dict[str, tuple[float, float]], fail_closed: bool | None = None, name: str = 'multi')
Multi-unit sliding window limiter (pages/records/seconds/chars/calls).
Source code in azure_bootstrap/ratelimit/__init__.py
fastapi_rate_limit
¶
FastAPI dependency factory. 429 + empty body on rejection.
detail is intentionally ignored by default — leak-resistant. Passing
a string opts into showing it (not recommended for public endpoints).
Source code in azure_bootstrap/ratelimit/__init__.py
webhook_bucket
¶
webhook_bucket(*, name: str = 'webhook') -> TokenBucket
Preset for Microsoft-Graph-style webhooks: 240 burst, 4/s sustained.