Classes
RateLimitBackend
1
▼
Protocol for rate limit storage backends.
RateLimitBackend
1
▼
Protocol for rate limit storage backends.
Methods
check_and_update
5
tuple[bool, int]
▼
Check if allowed, increment, and optionally block. Returns (allowed, retry_afte…
async
check_and_update
5
tuple[bool, int]
▼
async def check_and_update(self, key: str, now: float, *, requests: int, window_seconds: int, block_seconds: int) -> tuple[bool, int]
Check if allowed, increment, and optionally block. Returns (allowed, retry_after).
Parameters
| Name | Type | Description |
|---|---|---|
key |
— |
|
now |
— |
|
requests |
— |
|
window_seconds |
— |
|
block_seconds |
— |
Returns
tuple[bool, int]
AuthRateLimitConfig
7
▼
Configuration for auth endpoint rate limiting.
AuthRateLimitConfig
7
▼
Configuration for auth endpoint rate limiting.
Attributes
| Name | Type | Description |
|---|---|---|
requests |
int
|
— |
window_seconds |
int
|
— |
block_seconds |
int
|
— |
methods |
tuple[str, ...]
|
— |
paths |
tuple[str, ...]
|
— |
key_header |
str | None
|
— |
backend |
RateLimitBackend | None
|
— |
_InMemoryRateLimitBackend
2
▼
In-memory rate limit backend.
_InMemoryRateLimitBackend
2
▼
In-memory rate limit backend.
Methods
check_and_update
5
tuple[bool, int]
▼
async
check_and_update
5
tuple[bool, int]
▼
async def check_and_update(self, key: str, now: float, *, requests: int, window_seconds: int, block_seconds: int) -> tuple[bool, int]
Parameters
| Name | Type | Description |
|---|---|---|
key |
— |
|
now |
— |
|
requests |
— |
|
window_seconds |
— |
|
block_seconds |
— |
Returns
tuple[bool, int]
Internal Methods 1 ▼
__init__
0
▼
__init__
0
▼
def __init__(self) -> None
AuthRateLimitMiddleware
2
▼
Rate limiter for authentication-related endpoints.
AuthRateLimitMiddleware
2
▼
Rate limiter for authentication-related endpoints.
Methods
Internal Methods 2 ▼
__init__
1
▼
__init__
1
▼
def __init__(self, config: AuthRateLimitConfig | None = None) -> None
Parameters
| Name | Type | Description |
|---|---|---|
config |
— |
Default:None
|
__call__
2
AnyResponse
▼
async
__call__
2
AnyResponse
▼
async def __call__(self, request: Request, next: Next) -> AnyResponse
Parameters
| Name | Type | Description |
|---|---|---|
request |
— |
|
next |
— |
Returns
AnyResponse
Functions
redis_rate_limit_backend
2
RateLimitBackend
▼
Create a Redis-backed rate limit backend. Requires ``pip install chirp[redis]``.
redis_rate_limit_backend
2
RateLimitBackend
▼
def redis_rate_limit_backend(redis_url: str, key_prefix: str = 'chirp:ratelimit:') -> RateLimitBackend
Create a Redis-backed rate limit backend. Requirespip install chirp[redis].
Parameters
| Name | Type | Description |
|---|---|---|
redis_url |
str |
|
key_prefix |
str |
Default:'chirp:ratelimit:'
|
Returns
RateLimitBackend