Skip to content

common_rates.schemas.configs

What a limiter is told: which backend keeps the shared state, and how a caller waits.

One config per backend, discriminated by backend. The quotas themselves are not configuration: they are declared per scope on the limiter, since a vendor’s limits are facts the consumer states, not tuning.

Classes

MemoryLimiterConfig

Bases: _LimiterConfig

One process; the state lives in memory and dies with it.

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

backend

backend: Literal['memory'] = 'memory'

PostgresLimiterConfig

Bases: _LimiterConfig

Every process sharing the database shares the count.

The clock is the server’s, so processes cannot drift apart. The database is reached through common-db: connection and pool build an owned DBClient; both absent means a DBClient is borrowed at construction. target names the plane on a multi-target client, the default when None.

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

backend

backend: Literal['postgres'] = 'postgres'

connection

connection: DBConnectionConfig | None = Field(default=None, repr=False)

operation_timeout_sec

operation_timeout_sec: float = Field(default=10.0, gt=0, allow_inf_nan=False)

pool

pool: PoolConfig = Field(default_factory=(lambda: PoolConfig(min_size=0, max_size=4, timeout=5.0)), description="A limiter's pool is small and fails fast: an admission must not wait on a dead server.")

schema_name

schema_name: str = Field(default='common_rates', min_length=1, pattern='^[a-z_][a-z0-9_]*$')

target

target: str | None = None

RedisLimiterConfig

Bases: _LimiterConfig

Every process sharing the Redis or Dragonfly instance shares the count.

Declared so a deployment can be described today; the backend lands when the platform enables the service. Creating a limiter from it refuses until then.

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

backend

backend: Literal['redis'] = 'redis'

prefix

prefix: str = Field(default='common_rates', min_length=1)

url

url: SecretStr = Field(min_length=1, repr=False, exclude=True)

Functions

limiter_config

def limiter_config(value: Any) -> MemoryLimiterConfig | PostgresLimiterConfig | RedisLimiterConfig

One config from a config, a mapping, or nothing (memory).