tagz

A lightweight, type-safe Python library for building and parsing HTML documents programmatically — no templates, no DSL, just Python objects that map directly to HTML elements.

30-second tour

from tagz import Page, html

page = Page(
    lang="en",
    body_element=html.body(
        html.h1("Hello"),
        html.p("from ", html.strong("tagz")),
    ),
    head_elements=(
        html.meta(charset="utf-8"),
        html.title("tagz"),
    ),
)

output = page.to_html5(pretty=True)
assert "<!doctype html>" in output
assert "<strong>tagz</strong>" in output.replace("\n", "").replace("\t", "")

Pick the doc that fits your need

📘 Tutorials

Learning-oriented. Step-by-step lessons that take you from zero to working code. Start here if you’re new.

Tutorials
🛠 How-to guides

Task-oriented. Self-contained recipes that solve a single problem — streaming, parsing, escaping, embedding binary data, and more.

How-to guides
📖 Reference

Information-oriented. The exhaustive API surface: every class, every method, every option, with type signatures.

Reference
💡 Explanation

Understanding-oriented. The “why” — design decisions, the escaping model, callables and laziness, and the tagz.aio streaming model.

Explanation

Install

pip install tagz
# or with uv:
uv add tagz

Requires Python 3.10+. See Installation for project-integration notes.