Skip to content

common_rates

Shared rate limits: one limiter every process consults before it calls a counterparty.

Declare a vendor’s quotas per scope, then admit each call against all of them at once. The state lives in a backend, memory for one process or PostgreSQL through common-db for every process sharing an account, and the clock is the backend’s. The admission callable plugs straight into common-http’s admit hook.

from common_rates import Limiter, Quota, Scope
fmp = Scope(vendor="fmp", account="prod")
limiter = Limiter.postgres(connection).declare(fmp, Quota.per_minute(300), Quota.per_day(250_000))
async with limiter:
await limiter.acquire(fmp) # waits, or raises Refused
admit = limiter.admission(fmp) # for HttpClient(admit=admit)