pyrate_limiter.abstracts.store module

Storage for constant-state algorithms.

class pyrate_limiter.abstracts.store.StateStore

Bases: ABC

Holds one key’s state for a StateAlgorithm.

The store’s only real job is atomicity: check() must read the state, apply the transition and persist the result without another writer interleaving. How it achieves that is its own business - a lock in-process, a Lua script in Redis.

abstractmethod check(algorithm, rates, now, weight)

Apply algorithm.step to the stored state, atomically.

Return type:

Decision | Awaitable[Decision]

close()

Release any resources held. Optional.

Return type:

None

default_clock = <pyrate_limiter.clocks.MonotonicClock object>

Used when the bucket is not given a clock. Shared stores override it, since a monotonic clock means nothing across machines.

is_async = False

None means “ask the Leaker to probe” (a client that may be either).

abstractmethod read(algorithm, rates)

Current state. For reporting only - never the basis of a decision.

Return type:

Tuple[float, ...] | Awaitable[Tuple[float, ...]]

abstractmethod reset()

Forget everything, as though the key had never been used.

Return type:

None | Awaitable[None]