Skip to main content

simplify your HTML building.

Project description

haitch logo

simplify your HTML building.

builds.sr.ht status PyPI - Version

haitch

alternative pronunciation for the letter "H"

My goal is to make writing HTML as fun as writing Python.

Features

  • HTML element builder.
  • 100% test and type coverage.
  • No dependencies.
  • Documentation for common elements.

Quickstart

Install haitch using pip:

$ pip install haitch

Importing the package like so, allows you to build any element you like:

import haitch as H

# Render known `h1` tag.
print(H.h1("Hello, world"))
# <h1>Hello, world</h1>

# Render custom `foo` tag (useful for web components).
print(H.foo("Hello, world"))
# <foo>Hello, world!</foo>

# Fetch emails from data store.
emails = ["jane@aol.com", "bob@example.com", "mark@mail.org"]

# Build an ordered list of emails with ".com" domains.
email_list = H.ol(class_="emails")(
    H.li(H.a(href=f"mailto:{email}")(email))
    for email in sorted(emails)
    if email.endswith(".com")
)

print(email_list)
# <ol class="email-list">
#   <li>
#     <a href="mailto:bob@example.com">bob@example.com</a>
#   </li>
#   <li>
#     <a href="mailto:jane@aol.com">jane@aol.com</a>
#   </li>
# </ol>

Note: printed output above is prettified for readability, but the actual output is minified.

If you want to see how you can hook haitch into your web application, see the FastAPI and Django examples.

Motivation

Inspired by the htbuilder library as an alternative to templating. The library met most of my needs, but lacked type annotations and documentation for HTML elements and attributes. This made me consistently context switch between the MDN docs and my editor. This library attempts to solve this problem by bringing the HTML spec to where you program.

Non-goals

The following features will not be supported:

  • Deprecated elements and attributes: if you want to use them, you can since haitch supports generic elements and attributes. However, I am not going to write the annotations and documentation for them.
  • 100% input validation: this library is meant to assist the developer to write valid HTML with the help of type annotations and documentation. In the end, it is up to the developer and browser to verify that the input is of the correct type. So for example, I will not add any validation to make sure that a <col> element is directly nested inside of a <colgroup> element or that the span attribute for the <col> element is a positive integer.

Contributing

You can setup your local git clone to send email to the mailing list with:

git config sendemail.to '~loges/haitch-dev@lists.sr.ht'

Additional help for setting up git send-email.

License

haitch is distributed under the terms of the BSD-3-Clause license.

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

haitch-0.13.0.tar.gz (50.0 kB view details)

Uploaded Source

Built Distribution

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

haitch-0.13.0-py3-none-any.whl (98.9 kB view details)

Uploaded Python 3

File details

Details for the file haitch-0.13.0.tar.gz.

File metadata

  • Download URL: haitch-0.13.0.tar.gz
  • Upload date:
  • Size: 50.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.14.3 HTTPX/0.28.1

File hashes

Hashes for haitch-0.13.0.tar.gz
Algorithm Hash digest
SHA256 0926f71ab5e9c551baca316851a78aa4c2f2498d82925ae1f3ffe2aceac31a2c
MD5 eec4bafb04df42edde29479d36caa88f
BLAKE2b-256 17ce230a80f70c59bbf3bf890a6157cb4f21ae0f5da0cb13f39502fb33067461

See more details on using hashes here.

File details

Details for the file haitch-0.13.0-py3-none-any.whl.

File metadata

  • Download URL: haitch-0.13.0-py3-none-any.whl
  • Upload date:
  • Size: 98.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.14.3 HTTPX/0.28.1

File hashes

Hashes for haitch-0.13.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ccc24765d00c7d1fd03bcc87ea07d55cea397f7fb06a22ef0f042223ea08a867
MD5 215bef59a1591b75f60cd206f9fe2e06
BLAKE2b-256 9e1c1f9e4752f0adbd2c8f83576c30aa8d4548c0f0b833d945c466d55f1fdc54

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