API reference#

Everything below is importable from the top-level anza package (from anza import Setup), except the framework helpers in anza.adapters. Every page is generated from the docstrings in the source.

Operations#

Setup(root[, signing, watch, fragments, ...])

Where the templates are and how to render and sign them.

Page(route[, params])

Render the page for a request route into a full HTML document.

Fragment(template, slot[, params])

Render one template into an Envelope for a slot.

Stream(template, slot[, params])

Render one template as a Server-Sent Event in one call.

Engine and templates#

Engine(root, cache[, signing, fragments])

Loaded templates plus the validated signing key.

SignOptions([mode, secret, private_key, ...])

How fragments are signed.

SignMode

How envelopes are signed: "none" (no signature), "hmac" (HMAC-SHA256 with a shared secret) or "ed25519" (Ed25519 with a private key).

CacheStore([templates])

The loaded templates, by name.

Template(name, path, raw, digest, chunks[, ...])

One parsed template, compiled once for fast binding.

Chunk(kind, value)

One piece of a parsed template.

extract(template)

Split a template into static text and {{slot}} / {{{raw}}} chunks.

string(chunks[, params, escape])

Bind params into parsed chunks.

escape_html(text)

HTML-escape text for element content or a quoted attribute value.

Results#

Document(html)

A rendered page, from Page.

Envelope(slot, ts, html[, sig, css, v])

A rendered fragment on the wire, envelope format v2.

Manifest([templates])

Template names mapped to the SHA-256 digest of their source.

Signing and verification#

Signer()

A validated signing key, built once at setup.

VerifyKey(mode[, secret, public_key])

The key verify_envelope() checks a signature with.

verify_envelope(key, envelope, *, ...[, ...])

Verify a received envelope.

signature_message(ts, slot, html[, css])

The exact bytes a v2 envelope signature covers.

ENVELOPE_VERSION

Envelope wire-format version produced and accepted by this engine.

crypto.hmac

HMAC-SHA256 signatures in lowercase hex (available as anza.hmac).

crypto.ed25519

Ed25519 signing and verification (available as anza.ed25519).

crypto.hkdf

HKDF-SHA256 key derivation (available as anza.hkdf).

crypto.digest

SHA-256 digests (available as anza.digest).

Streaming#

format_event(envelope)

Frame an envelope as one Server-Sent Event.

format_packet(envelope)

The WebSocket text message for an envelope: its compact JSON.

Errors#

AnzaError(code, message)

An engine error with a stable code.

Adapters#

adapters.fastapi

FastAPI / Starlette responses for pages and envelopes.

adapters.flask

Flask responses for pages and envelopes.

adapters.asgi

Raw ASGI responses for pages and envelopes.

adapters.wsgi

Raw WSGI responses for pages and envelopes.