Skip to content

API reference

Auto-generated from the source docstrings via mkdocstrings. Everything below is reachable from the import deadbolt as db alias.

Core

deadbolt.Auth

Configures deadbolt and exposes the request handler and direct-call API.

A single instance is the entire mental model: auth.handle serves HTTP, auth.api calls endpoints directly, and auth.asgi_app / auth.wsgi_app return mountable apps.

api property

Namespace of endpoints callable directly, without HTTP.

handle(request) async

Route request to an endpoint and return the response.

handle_sync(request)

Serve request from synchronous (WSGI) code via the sync bridge.

close()

Shut down the background loop backing the sync bridge, if started.

cleanup_expired() async

Delete expired sessions and verifications; run periodically in production.

asgi_app()

Return a mountable ASGI application; mount it at base_path.

wsgi_app()

Return a mountable WSGI application; mount it at base_path.

deadbolt.EmailPassword dataclass

deadbolt.SessionConfig dataclass

deadbolt.CookieConfig dataclass

HTTP contract

deadbolt.AuthRequest dataclass

A framework-neutral request handed to the core.

body is the raw, unparsed payload: adapters must not consume the request stream before building this, or the core cannot read it.

deadbolt.AuthResponse dataclass

A framework-neutral response returned by the core.

cookies are carried as structured data rather than raw Set-Cookie headers so adapters can apply them via the framework's own response object.

deadbolt.Cookie dataclass

A cookie to set, applied by each adapter through its native cookie API.

Database

deadbolt.Where dataclass

A single filter condition, combined with others by connector.

deadbolt.FieldSpec dataclass

A column definition, including deadbolt's custom-field attributes.

deadbolt.TableSpec dataclass

A logical table assembled from core, plugin, and user fields.

deadbolt.SortBy dataclass

deadbolt.MemoryAdapter

A dict-backed :class:~deadbolt.protocols.AsyncDatabaseAdapter.

Protocols

deadbolt.AsyncDatabaseAdapter

Bases: Protocol

deadbolt.Hasher

Bases: Protocol

Password hashing with a rehash-on-verify upgrade path.

deadbolt.SessionStore

Bases: Protocol

Optional secondary store for cached sessions (e.g. Redis).

deadbolt.EmailSender

Bases: Protocol

Delivers verification and password-reset messages.

deadbolt.SmsSender

Bases: Protocol

Delivers SMS one-time codes (used by the phone-number plugin).

Hooks

deadbolt.Hook dataclass

A hook bound to an exact path (or all paths when path is None).

deadbolt.HookContext dataclass

deadbolt.Hooks dataclass

Plugins

deadbolt.Plugin dataclass

A unit of extension contributing endpoints, hooks, and, optionally, tables.

Rate limiting

deadbolt.RateLimit dataclass

Global window/max plus per-path rule overrides.

deadbolt.RateLimitRule dataclass

A per-path override; path matches an endpoint path exactly.

deadbolt.RateLimitStore

Bases: Protocol

Counts hits per key within a window; return the running count.

Errors

deadbolt.errors

Exception hierarchy for deadbolt.

AuthError

Bases: Exception

Base class for every error raised by deadbolt.

ConfigError

Bases: AuthError

Raised when the Auth configuration is invalid or a secret is missing.

APIError

Bases: AuthError

An error mapped to an HTTP response.

Endpoints raise this to signal a client- or server-facing failure. Adapters translate it into an AuthResponse with the given status.

is_api_error(error)

Return whether error is an :class:APIError.