anza#
0.6.0 · Python engine
Server-templated UI for Python, signed.
Render full HTML pages and signed JSON fragment envelopes from plain
.html templates. Parsed once at startup, bound with plain Python data,
byte-identical to the Rust and TypeScript engines.
# Python 3.10+, installs cryptography>=42
pip install anza
Overview#
Anza server-templated UI (STUI) engine for Python.
anza renders full HTML pages and signed JSON fragment envelopes from
plain .html templates with {{slot}} placeholders. Templates are
loaded and parsed once, at startup; a render is a dictionary lookup per slot
and one string format. It needs Python 3.10+ and cryptography>=42 (for
Ed25519, installed with the package); everything else is the standard
library.
The engine follows the shared Engine Contract, so it renders the same bytes, envelopes and signatures as the Rust and TypeScript engines.
The public API is re-exported here:
Operations:
Setup(load templates, build anEngine),Page,FragmentandStream.Results:
Document(a page),Envelope(a fragment, wire format v2) andManifest.Signing:
SignOptions,Signer,VerifyKey,verify_envelope(),signature_message()and thehmac,ed25519,hkdfanddigestmodules.Templates:
Template,Chunk,extract(),string()andescape_html().Streaming:
format_event()(SSE) andformat_packet()(WebSocket).Errors:
AnzaError.
Framework helpers live in anza.adapters.
Example
Load the templates once, then render a page and a signed fragment:
from anza import Fragment, Page, Setup, SignOptions
engine = Setup(
root="./templates",
signing=SignOptions(mode="hmac", secret="a-secret-of-at-least-32-bytes!!!"),
).run()
doc = Page("/", {"title": "Home"}).run(engine) # pages/home.html
env = Fragment("feed/card.html", "feed", {"title": "New"}).run(engine)
body = env.to_json() # {"v":2,"slot":"feed","ts":...,"html":...,"sig":...}
Warning
Values are inserted without HTML escaping unless the engine is set up
with escape=True (see Setup). Escape untrusted input with
escape_html() or turn the option on.
Install#
pip install anza
anza needs Python 3.10 or newer. Its only dependency is
cryptography>=42, which provides Ed25519 and is installed with the
package.
Next steps#
Setup: the template root, fragment allowlist, escaping, size limit and reloading.
Rendering: pages, fragments, data binding and escaping.
Signing & verification: keys, the v2 signature and
verify_envelope().Streaming: SSE and WebSocket framing.
Framework adapters: FastAPI, Flask, ASGI and WSGI helpers.
API reference: every public class and function.
Engine Contract: the behaviour shared by the Rust, TypeScript and Python engines.