Skip to main content

fastertags, an HTML tag library

A typesafe library for writing HTML in Python:

import fastertags as h

if __name__ == "__main__":
    doc = h.html(
        h.head(
            h.title("An example document"),
        ),
        h.body(
            h.h1("Title"),
            h.p(class_="css-class-name")("some paragraph"),
            h.p("Some more paragraph"),
        ),
    )
    print(doc)

yields

<!DOCTYPE html><html><head><title>An example document</title></head><body><h1>Title</h1><p class="css-class-name">some paragraph</p><p>Some more paragraph</p></body></html>

Tags and Attributes are scraped from the WHATWG HTML Spec at https://html.spec.whatwg.org/. Version numbers reflect when the scraping was done, the current version 0.2024.11 was taken in December 2024.

HTMX

fastertags is a standalone building block for fasterhtml, which in turn uses HTMX. Most notably, fastertags serializes event-handler on* attributes as hx-on:*, for example hx-on:click instead of onclick.

This can be changed by setting HTMLElement.EVENT_HANDLER_PREFIX:

doc = h.h1().on("click", "alert('clicked')")("Title")

print(doc)
# <h1 hx-on:click="alert('clicked')">Title</h1>

h.HTMLElement.EVENT_HANDLER_PREFIX= "on"

print(doc)
# <h1 onclick="alert('clicked')">Title</h1>

Scoped CSS

fastertags emulates the scoped attributes on <style> tags by wrapping its contents in @scope { ... }. The h.style() function does feature the boolean attribute scoped that allows for True, False, or None. The default is None, which means contents will be wrapped in @scope { ... } if the element is not serialized as the child of a head element:

doc = h.html(
    h.head(
        h.style("not scoped"),
    ),
    h.body(
        h.style("scoped"),
    ),
)
print(doc)

yields

<!DOCTYPE html><html><head><style>not scoped</style></head><body><style>@scope {scoped}</style></body></html>

Metadata

Release files for fastertags 0.2024.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for fastertags 0.2024.11
File Interpreter ABI Platform Actions
fastertags-0.2024.11-py3-none-any.whl Python 3 none any Details for fastertags-0.2024.11-py3-none-any.whl

Release files / fastertags-0.2024.11-py3-none-any.whl

Download URL fastertags-0.2024.11-py3-none-any.whl
Size 22.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
469a8bee899bf4f447eddbd635feaf894e6a27a87e8cd0692d61763bfd8fc5ac
BLAKE2b-256 checksum
How to use checksums
081d476d5ff1295523d25b3bb2fb9ae6054ab135d4cb557fef4e0d58737fb113
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Security for fastertags 0.2024.11

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page