Results#

class Document(html: str)[source]#

A rendered page, from Page.

str(document) is the HTML.

Example

>>> from anza import Page, Setup
>>> doc = Page("/", {"title": "Hi"}).run(Setup(root="templates").run())
>>> str(doc) == doc.html
True
>>> doc.to_bytes()[:12]
b'<html><body>'
html: str#

The full HTML document.

to_bytes() → bytes[source]#

The HTML encoded as UTF-8, ready for a response body.

class Envelope(slot: str, ts: int, html: str, sig: str | None = None, css: str | None = None, v: int = 2)[source]#

A rendered fragment on the wire, envelope format v2.

Produced by Fragment. The JSON form is {"v":2,"slot":...,"ts":...,"html":...,"sig":...} (sig and css only when set), byte-identical to the Rust and TypeScript engines (see the Engine Contract).

Example

>>> from anza import Envelope
>>> env = Envelope(slot="feed", ts=1700000000, html="<p>Hi</p>")
>>> env.to_json()
'{"v":2,"slot":"feed","ts":1700000000,"html":"<p>Hi</p>"}'
>>> env.to_dict()["v"]
2
slot: str#

The client slot the HTML is for.

ts: int#

Render time, in Unix seconds.

html: str#

The rendered HTML.

sig: str | None = None#

Lowercase-hex signature over message(), or None when the engine does not sign.

css: str | None = None#

Optional CSS shipped with the HTML; covered by the signature.

v: int = 2#

Wire-format version, always 2 for envelopes this engine produces.

message() → bytes[source]#

The exact bytes the signature covers.

Returns:

bytes – signature_message(ts, slot, html, css), see signature_message().

to_dict() → dict[str, Any][source]#

The envelope as a JSON-ready dict.

Returns:

dict – v, slot, ts and html, plus sig and css when they are set.

to_json() → str[source]#

Compact JSON, byte-identical to the Rust and TypeScript engines.

Returns:

str – The JSON text, v first, no whitespace.

class Manifest(templates: dict[str, str] = ...)[source]#

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

Build one with CacheStore.manifest() to compare template versions across servers or deployments.

Example

>>> from anza import Manifest
>>> m = Manifest()
>>> m.insert("feed/card.html", "ab12")
>>> m.get("feed/card.html"), m.get("other.html")
('ab12', None)
templates: dict[str, str]#

Lowercase-hex SHA-256 digests by template name.

insert(name: str, digest: str) → None[source]#

Record the digest of the template called name.

get(name: str) → str | None[source]#

The digest of the template called name, or None.