Skip to main content

Rust-backed framework for building websites in pure Python

Project description

ztml

A Rust-backed framework for building websites in pure Python. Define HTML, CSS, and JS using Python expressions with full autocompletion. Inspired by FastHTML.

Read my documentation

Install

pip install ztml

Quick example

from ztml import *

page = render(
    Html(
        Head(Meta().charset("utf-8"), Title("My App")),
        Body(
            H1("Hello, ztml!"),
            P("Build websites with Python.").cls("intro"),
            A("GitHub").href("https://github.com").target("_blank"),
        ),
    )
)

Every HTML element has a constructor. Attributes are set via chained builder methods. CSS is built with Rule, Media, and Keyframes, with 400+ typed property methods generated from W3C specs:

Style(
    Rule("body").margin("0").font_family("system-ui, sans-serif"),
    Rule(".container").display("flex").gap("1rem").padding("2rem"),
    Media("max-width: 768px",
        Rule(".container").flex_direction("column"),
    ),
)

The built-in server handles routing, sessions, SSE, and WebSockets:

from ztml import *
from ztml.scripts import HTMX
from ztml.server import rt, serve

@rt('/')
def get():
    return Html(
        Head(Title("Counter"), HTMX),
        Body(
            H1("Counter"),
            P("0").id("count"),
            Button("Increment").hx_post("/increment").hx_target("#count"),
        ),
    )

count = 0

@rt('/increment')
def post():
    global count
    count += 1
    return P(str(count)).id("count")

serve()  # localhost:5001

See the docs for the full guide on HTML elements, CSS styling, JavaScript helpers, custom components, and the server layer.

Examples

uv run examples/static_page.py > page.html
uv run examples/counter_server.py
uv run examples/todo_server.py
uv run examples/auth_app.py
uv run examples/ws_chat.py
uv run examples/sse_clock.py

Benchmarks

Compared against FastHTML building and rendering nested HTML element trees:

Scenario         Library      Elements   Build (ms)   Render (ms)   Total (ms)
---------------------------------------------------------------------------
10x50            ztml             1040         1.44          0.09         1.54
10x50            fasthtml         1040        14.72          2.62        17.35
                             speedup: build 10.2x, render 28.5x, total 11.3x

50x100           ztml            10200        14.65          0.90        15.55
50x100           fasthtml        10200       151.36         26.12       177.61
                             speedup: build 10.3x, render 28.9x, total 11.4x

100x200          ztml            40400        58.04          3.63        61.69
100x200          fasthtml        40400       710.79        106.00       816.57
                             speedup: build 12.2x, render 29.2x, total 13.2x

^ benchmarks/bench.py (M3 Pro MacBook Pro)

Building from source

Prerequisites: Rust toolchain, Python 3.12+, uv.

uv sync
uv run maturin develop
cargo run --bin gen_stubs --no-default-features  # regenerate .pyi stubs

Running tests

uv run python -m pytest
cargo test -p ztml-core

Releasing

Bump the version in crates/ztml-core/Cargo.toml and crates/ztml-python/Cargo.toml, make sure stubs are up to date, then:

git add -A && git commit -m "bump version to 0.x.y"
git tag v0.x.y
git push && git push origin v0.x.y

The v* tag triggers the full build matrix (Linux, macOS, Windows) and publishes to PyPI.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ztml-0.2.5.tar.gz (56.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

ztml-0.2.5-cp314-cp314-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.14Windows x86-64

ztml-0.2.5-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

ztml-0.2.5-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64

ztml-0.2.5-cp314-cp314-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

ztml-0.2.5-cp314-cp314-macosx_10_12_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

ztml-0.2.5-cp313-cp313-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.13Windows x86-64

ztml-0.2.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

ztml-0.2.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

ztml-0.2.5-cp313-cp313-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

ztml-0.2.5-cp313-cp313-macosx_10_12_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

ztml-0.2.5-cp312-cp312-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.12Windows x86-64

ztml-0.2.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

ztml-0.2.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

ztml-0.2.5-cp312-cp312-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

ztml-0.2.5-cp312-cp312-macosx_10_12_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

Details for the file ztml-0.2.5.tar.gz.

File metadata

  • Download URL: ztml-0.2.5.tar.gz
  • Upload date:
  • Size: 56.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ztml-0.2.5.tar.gz
Algorithm Hash digest
SHA256 20493914492310eda6787431a7eb16ca2c4a6b0da2ffee2c4afa84ef89c1f5cf
MD5 a96eeb4796113cfb1c5ec12df0e3d33a
BLAKE2b-256 490a510cee1aa8c814be338a57e37055200d863e7e36baf82374729a9694b811

See more details on using hashes here.

Provenance

The following attestation bundles were made for ztml-0.2.5.tar.gz:

Publisher: ci.yml on bleemesser/ztml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ztml-0.2.5-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: ztml-0.2.5-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ztml-0.2.5-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 74241c009391e831654f458e1ef9d2258852cad51cf95f4f424b5ec9f0490f77
MD5 2ca245ab660f6f28813d164153864da0
BLAKE2b-256 87ce6e22480145a5b2411bfd0a2d093ab5a91458b097fd760466fa00ff586b22

See more details on using hashes here.

Provenance

The following attestation bundles were made for ztml-0.2.5-cp314-cp314-win_amd64.whl:

Publisher: ci.yml on bleemesser/ztml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ztml-0.2.5-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ztml-0.2.5-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4cf60f9c996f2b63f72de688c1908101b0af7070ee87a3f98b30844819848fb3
MD5 a2cea0354280237ab32366cc4771f1b2
BLAKE2b-256 477f79698485031d4ea9827c5de045436e03084c181e29c5a9949002c9a50178

See more details on using hashes here.

Provenance

The following attestation bundles were made for ztml-0.2.5-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: ci.yml on bleemesser/ztml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ztml-0.2.5-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ztml-0.2.5-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2622dea8e38e719698ddd4a66324339aeba2244fdb2f1e58f3e9edc3009fda97
MD5 4870cd786c14290919addc66aca007a9
BLAKE2b-256 e9b936b19fb66b7b26f2b025fc9378db4d19caf664f2f89ec73e4c67b044d051

See more details on using hashes here.

Provenance

The following attestation bundles were made for ztml-0.2.5-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: ci.yml on bleemesser/ztml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ztml-0.2.5-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ztml-0.2.5-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4a6543aff4e9ea7b19ea2864e7e5ef888fbb50e5a6cc9b615912d51178d6dd60
MD5 3476d48d2a167b30dfc09a8b8541fa58
BLAKE2b-256 fe4d92743ed793420291333cbce157e9f3e4d2571a4fe67f0da9dfa72db645f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for ztml-0.2.5-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: ci.yml on bleemesser/ztml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ztml-0.2.5-cp314-cp314-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ztml-0.2.5-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e1d6593e8db036d9a23c20eb98c40fd08204305c0773e15f2e71b71579f68f63
MD5 33bd4298c96136493fcfa0f4e1450ba6
BLAKE2b-256 fd6bc88749df17b7e61b9bfed402801ed4403a83da36ee000d22cef878d2b304

See more details on using hashes here.

Provenance

The following attestation bundles were made for ztml-0.2.5-cp314-cp314-macosx_10_12_x86_64.whl:

Publisher: ci.yml on bleemesser/ztml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ztml-0.2.5-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: ztml-0.2.5-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ztml-0.2.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e14d00da4f85c499e6be0c2d1ddc618b42bdea370079debae36718c834349320
MD5 6e070d56304f0eb8faa362b1e58f7584
BLAKE2b-256 c44330d16a208998c997d772191972f95d094c3fd37c10271b215ba0d554369b

See more details on using hashes here.

Provenance

The following attestation bundles were made for ztml-0.2.5-cp313-cp313-win_amd64.whl:

Publisher: ci.yml on bleemesser/ztml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ztml-0.2.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ztml-0.2.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2428661464a178bbf1bd33c951a20b5b4f3551d3433887c2444681fe0f1d183f
MD5 465296a40b31690db8fc8b436313c0ea
BLAKE2b-256 09557d532a21b23a802614c80fa85614e34c258274bee9dc5c299584b560f7e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for ztml-0.2.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: ci.yml on bleemesser/ztml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ztml-0.2.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ztml-0.2.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 029fa81b3089ccf6e6e5779dff53000c53095d02e459cfd8460f2a8e17449017
MD5 ac791599e3302129eea82ed6f7631ccf
BLAKE2b-256 a7debc30d665af6bbefaec1cbd01a3ff9a8a207ab76e7df1927c1df785bcc0c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for ztml-0.2.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: ci.yml on bleemesser/ztml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ztml-0.2.5-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ztml-0.2.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 451a299cdaab8d9a2121fc6361231db317de35893a8dc184065d8fc23d69532a
MD5 ef2f51b2e02ddcf6b4e97ec7d7c765d6
BLAKE2b-256 095ada46d4f1fbecd568e427af51647eb81ccfb8a22b18f0cbc4b1a257f58ca8

See more details on using hashes here.

Provenance

The following attestation bundles were made for ztml-0.2.5-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: ci.yml on bleemesser/ztml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ztml-0.2.5-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ztml-0.2.5-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e37e98d8bb77016b9e7b9dd0d1c194d25f899a9dd3e556ce9cff08e423608b18
MD5 f44d571cdd0ff7643e75cfc3a366f3a4
BLAKE2b-256 498c8e56c807be66c6be5df2ce189ebb9073c5ff9fe2320d69dabbe83495b3ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for ztml-0.2.5-cp313-cp313-macosx_10_12_x86_64.whl:

Publisher: ci.yml on bleemesser/ztml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ztml-0.2.5-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: ztml-0.2.5-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ztml-0.2.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9e7f54d7cbff5c64c2f8352fa723e79a7a9d566f3e8eaee4b75f04a97c8cd12f
MD5 bbc3099e25b114e039eba9c334751bc1
BLAKE2b-256 0afdd010787328c1772ffd6ee722a5a0f79105cf53195507fd38c90fe205d888

See more details on using hashes here.

Provenance

The following attestation bundles were made for ztml-0.2.5-cp312-cp312-win_amd64.whl:

Publisher: ci.yml on bleemesser/ztml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ztml-0.2.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ztml-0.2.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bd181cceacadc2d1bda403613389bf426e79e4bb31b893c950587e0bb1cd4140
MD5 2ac4ca9bebbe5be3ca9ba7fb07a97044
BLAKE2b-256 f910d26c6bd6d9d32d9f30f2fb08adc8c4aabccb335a8f47575179bf36a5f4f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for ztml-0.2.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: ci.yml on bleemesser/ztml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ztml-0.2.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ztml-0.2.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a551523f31219aa3f0ed75329fbb28413db90cef1a0b467dc008c60a908b1608
MD5 c97e8c75e98336498861858eaeeb6a2c
BLAKE2b-256 97ab02946ef452ca136d239bcf22c252835315182d6250e5ae67cf9d6fc3fd33

See more details on using hashes here.

Provenance

The following attestation bundles were made for ztml-0.2.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: ci.yml on bleemesser/ztml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ztml-0.2.5-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ztml-0.2.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4404952a8e0f8fdeecf3de86063852945767144954c08294c8fcb346b57f0e4f
MD5 acbf433d7eb1c3436e0ffdf84ce7a6bf
BLAKE2b-256 7133208020de46fba3d51b5c17d7312f24381af983facdd9bb497e9e9912b92c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ztml-0.2.5-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: ci.yml on bleemesser/ztml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ztml-0.2.5-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ztml-0.2.5-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b1a0eb7dab36ec161277a52da851ddc87c673792dcf0c19cd19fea70002d04fb
MD5 08a906163fc9c6e101dbfc50a3c5099e
BLAKE2b-256 414a0076716d080902c1c73a0de3b9464b578a096c8737fb1d45cb57652c52be

See more details on using hashes here.

Provenance

The following attestation bundles were made for ztml-0.2.5-cp312-cp312-macosx_10_12_x86_64.whl:

Publisher: ci.yml on bleemesser/ztml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page