Skip to content

common_rates.limiters.limiter

The front door: one Limiter over whichever backend the config names.

Every backend answers the same verbs with the same signatures, so the door delegates and never narrows. Construction is the only thing it adds: from a config, or the two spellings a caller reaches for most.

Classes

Limiter

One limiter for the application, over the backend its config names.

Carried state: the backend limiter it wraps, and nothing else.

Example: limiter = Limiter.memory().declare(Scope(vendor=“fmp”), Quota.per_minute(300)) async with limiter: await limiter.acquire(Scope(vendor=“fmp”)) http = HttpClient.create(base_url=…, admit=limiter.admission(Scope(vendor=“fmp”)))

__init__

def __init__(backend: BaseLimiter) -> None

Fields and properties declared here; inherited members belong to the bases above.

backend

Read-only property.

backend: BaseLimiter

The real limiter, for anything the door does not repeat.

scopes

Read-only property.

scopes: tuple[Scope, ...]

aclose

async def aclose() -> None

acquire

async def acquire(scope: Scope, cost: float = 1.0) -> Permit

admission

def admission(scope: Scope, cost: float = 1.0) -> Callable[..., Awaitable[None]]

balance

async def balance(scope: Scope) -> tuple[Balance, ...]

create

@classmethod
def create(config: Any = None, **resources: Any) -> Self

From a config, a mapping, or nothing (memory); extra resources, such as a borrowed DBClient, go to the backend’s constructor.

declare

def declare(scope: Scope, *quotas: Quota) -> Self

declared

def declared(scope: Scope) -> tuple[Quota, ...]

hold

async def hold(scope: Scope, seconds: float) -> None

info

def info() -> LimiterInfo

memory

@classmethod
def memory(**overrides: Any) -> Self

open

async def open() -> Self

postgres

@classmethod
def postgres(connection: DBConnectionConfig | Mapping[str, Any] | None = None, *, db: DBClient | None = None, pool: PoolConfig | Mapping[str, Any] | None = None, **overrides: Any) -> Self

An owned common-db client from a connection config, or a borrowed one; never both.