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.16.tar.gz (6.4 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.16-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: html_tags-0.0.16.tar.gz
  • Upload date:
  • Size: 6.4 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.16.tar.gz
Algorithm Hash digest
SHA256 f30574d577134542e96fafc5300e7bc08f388be1cc0e754cb3d6024d6f7b2506
MD5 5e0ef470902029ea37ddf01effe8b62c
BLAKE2b-256 d5d0c278ebe5ca3ce0bb8c7444a71c9b324eab266de97be8b7eaf14dcd3dc6af

See more details on using hashes here.

File details

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

File metadata

  • Download URL: html_tags-0.0.16-py3-none-any.whl
  • Upload date:
  • Size: 7.7 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.16-py3-none-any.whl
Algorithm Hash digest
SHA256 3cb39b6898b2829cf860917b7950ef79fd0c89c56cd671a40026767030f4bc75
MD5 1448fbc109d03650c82f835b0e2a479d
BLAKE2b-256 f1896ef6a7b65d59b3b98a4c7a4aff8f753b815a249f47dee3f26826dcdd9aac

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