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:

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#