Skip to main content

Concise, immutable HTML/SVG generation for Python. Zero dependencies.

Project description

html-tags

PyPI version

[!WARNING] Under active development — Mar 2026

Concise, immutable HTML/SVG generation for Python. Zero dependencies.

from html_tags import setup_tags, setup_svg
setup_tags(); setup_svg()

page = Html(
    Head(Title("hello")),
    Body(
        H1("hello world", cls="title"),
        Svg(Circle(cx="50", cy="50", r="40")),
    )
)

Tags are immutable — call to add children or attributes:

Div(cls="card")("content", id="main")

SVG elements self-close correctly (<line />) and shapes like Circle accept children for animations.

Datastar SSE helpers included:

from html_tags import patch_elements, patch_signals, datastar_stream

Gotchas

Keyword attribute names convert _ to -:

Circle(stroke_width="2")  # → stroke-width="2"

Dict keys pass through verbatim — use for special syntax or reserved names:

Div({"data-on:click__once": "@post('/api')"})
FeBlend({"mode": "multiply"})

HTML void elements render without slash (<br>), SVG elements self-close (<line />).

Security

Validates against injection, not HTML structure:

  • <script>/<style> content checked for closing tag injection
  • URL attributes reject javascript: and vbscript: schemes
  • Attribute names validated against injection patterns
  • Void elements reject children, <html> rejects nesting

Structural correctness (e.g. <li> inside <ul>) is left to the browser.

Install

pip install html-tags

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

html_tags-0.0.19.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

html_tags-0.0.19-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file html_tags-0.0.19.tar.gz.

File metadata

  • Download URL: html_tags-0.0.19.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for html_tags-0.0.19.tar.gz
Algorithm Hash digest
SHA256 278a1162e21a32e4f7d621a1767f9ef80400a6063940ac41e4dfe60e39936cbf
MD5 b3d20ae4f620edd041e57915f5c40b26
BLAKE2b-256 1171882f787b05491c0f64628fc8d2b77a0013816d8e7ee8aedf1fe0168e998b

See more details on using hashes here.

File details

Details for the file html_tags-0.0.19-py3-none-any.whl.

File metadata

  • Download URL: html_tags-0.0.19-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for html_tags-0.0.19-py3-none-any.whl
Algorithm Hash digest
SHA256 071300f3d52d58875df5a3b89263b642381400c4221480e8dca2b07b80bf6688
MD5 c1a1dc9246d84b9a425807d7d1762f99
BLAKE2b-256 7443034bc9274613eaea1b503a699c62160c733f3585e47f4a15168c962f451a

See more details on using hashes here.

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