Module

security.lockout

Login lockout primitives.

Framework-level helper for tracking repeated authentication failures. Applications call this from login handlers. Supports pluggable backends for Redis-backed lockout across workers.

Classes

LockoutBackend 3
Protocol for lockout storage backends.

Protocol for lockout storage backends.

Methods

is_locked 1 tuple[bool, int]
Return (is_locked, retry_after_seconds).
def is_locked(self, key: str) -> tuple[bool, int]
Parameters
Name Type Description
key
Returns
tuple[bool, int]
record_success 1
Clear failure state after successful auth.
def record_success(self, key: str) -> None
Parameters
Name Type Description
key
record_failure 1 tuple[bool, int]
Record failure and return (is_locked, retry_after_seconds).
def record_failure(self, key: str) -> tuple[bool, int]
Parameters
Name Type Description
key
Returns
tuple[bool, int]
LockoutConfig 6
Lockout policy configuration.

Lockout policy configuration.

Attributes

Name Type Description
max_failures int
window_seconds int
base_lock_seconds int
backoff_multiplier float
max_lock_seconds int
backend LockoutBackend | None
_InMemoryLockoutBackend 4
In-memory lockout backend.

In-memory lockout backend.

Methods

is_locked 1 tuple[bool, int]
def is_locked(self, key: str) -> tuple[bool, int]
Parameters
Name Type Description
key
Returns
tuple[bool, int]
record_success 1
def record_success(self, key: str) -> None
Parameters
Name Type Description
key
record_failure 1 tuple[bool, int]
def record_failure(self, key: str) -> tuple[bool, int]
Parameters
Name Type Description
key
Returns
tuple[bool, int]
Internal Methods 1
__init__ 1
def __init__(self, config: LockoutConfig) -> None
Parameters
Name Type Description
config
LoginLockout 4
Track login failures and compute lockout windows.

Track login failures and compute lockout windows.

Methods

is_locked 1 tuple[bool, int]
Return lock status and retry-after seconds.
def is_locked(self, key: str) -> tuple[bool, int]
Parameters
Name Type Description
key
Returns
tuple[bool, int]
record_success 1
Clear failure state after successful authentication.
def record_success(self, key: str) -> None
Parameters
Name Type Description
key
record_failure 1 tuple[bool, int]
Record a failed attempt and return lock status. Returns ``(is_locked, retry_af…
def record_failure(self, key: str) -> tuple[bool, int]

Record a failed attempt and return lock status.

Returns(is_locked, retry_after_seconds).

Parameters
Name Type Description
key
Returns
tuple[bool, int]
Internal Methods 1
__init__ 1
def __init__(self, config: LockoutConfig | None = None) -> None
Parameters
Name Type Description
config Default:None