The counters of a RateLimiter.
Functions#
fixed_window#
fixed_window(*, key, tokens, refill_rate_millis, limit) -> Effect[tuple[float, float], RateLimiterError]Add tokens to key's count, unless limit is given and
would be passed. Gives (count, ttl_millis): the count reached (or
that would be), and how long the window has left. Without a
limit each token extends the window by refill_rate_millis;
with one, the first positive admission into an empty or expired key
opens a window of refill_rate_millis * limit that later
admissions don't extend.
| Parameter | Type | Description |
|---|---|---|
key | str | |
tokens | float | |
refill_rate_millis | float | |
limit | float | None |
Returns Effect[tuple[float, float], RateLimiterError]
def fixed_window(
self, *, key: str, tokens: float, refill_rate_millis: float, limit: float | None
) -> Effect[tuple[float, float], RateLimiterError]:
"""Add ``tokens`` to ``key``'s count, unless ``limit`` is given and
would be passed. Gives ``(count, ttl_millis)``: the count reached (or
that would be), and how long the window has left. Without a
``limit`` each token extends the window by ``refill_rate_millis``;
with one, the first positive admission into an empty or expired key
opens a window of ``refill_rate_millis * limit`` that later
admissions don't extend."""
...token_bucket#
token_bucket(*, key, tokens, limit, refill_rate_millis, allow_overflow) -> Effect[tuple[float, float], RateLimiterError]Take tokens from key's bucket of limit, refilled one
token per refill_rate_millis; the balance goes below zero only
with allow_overflow. Gives (remaining, elapsed_millis): the
balance after the take, and the time since the last refill.
| Parameter | Type | Description |
|---|---|---|
key | str | |
tokens | float | |
limit | float | |
refill_rate_millis | float | |
allow_overflow | bool |
Returns Effect[tuple[float, float], RateLimiterError]
def token_bucket(
self,
*,
key: str,
tokens: float,
limit: float,
refill_rate_millis: float,
allow_overflow: bool,
) -> Effect[tuple[float, float], RateLimiterError]:
"""Take ``tokens`` from ``key``'s bucket of ``limit``, refilled one
token per ``refill_rate_millis``; the balance goes below zero only
with ``allow_overflow``. Gives ``(remaining, elapsed_millis)``: the
balance after the take, and the time since the last refill."""
...adaptive_consume#
adaptive_consume(*, key, tokens, fallback_limit, fallback_window) -> Effect[AdaptiveConsumeResult, RateLimiterError]See RateLimiterService.adaptive_consume.
| Parameter | Type | Description |
|---|---|---|
key | str | |
tokens | float | |
fallback_limit | float | |
fallback_window | Duration |
Returns Effect[AdaptiveConsumeResult, RateLimiterError]
def adaptive_consume(
self, *, key: str, tokens: float, fallback_limit: float, fallback_window: Duration
) -> Effect[AdaptiveConsumeResult, RateLimiterError]:
"""See ``RateLimiterService.adaptive_consume``."""
...adaptive_feedback#
adaptive_feedback(*, key, epoch, tokens, status, retry_after) -> Effect[None, RateLimiterError]See RateLimiterService.adaptive_feedback.
| Parameter | Type | Description |
|---|---|---|
key | str | |
epoch | int | |
tokens | float | |
status | int | |
retry_after | Duration | None |
Returns Effect[None, RateLimiterError]
def adaptive_feedback(
self, *, key: str, epoch: int, tokens: float, status: int, retry_after: Duration | None
) -> Effect[None, RateLimiterError]:
"""See ``RateLimiterService.adaptive_feedback``."""
...