simplify your HTML building.
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
haitchsupports 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 thespanattribute for the<col>element is a positive integer.
Contributing
- issue tracker: issues for bugs and features.
- mailing list: discussion, announcements, and patches.
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
and adheres to the REUSE Specification.
Metadata
Release files for haitch 0.15.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| haitch-0.15.0.tar.gz | 59.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| haitch-0.15.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 165.1 kB
Release files / haitch-0.15.0.tar.gz
| Download URL | haitch-0.15.0.tar.gz |
|---|---|
| Size | 59.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
95e8b0af92d6b97757935a6508f447494a463379066ae579c248f0231d4bb1f1
|
|
BLAKE2b-256 checksum How to use checksums |
07cc18e3cfe86e43a36f9e04abedd489c44445004a5678319f57c99ed2a32325
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Hatch/1.16.5 cpython/3.14.3 HTTPX/0.28.1
|
Release files / haitch-0.15.0-py3-none-any.whl
| Download URL | haitch-0.15.0-py3-none-any.whl |
|---|---|
| Size | 105.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d98fbd5d1732bacc627eab99cd918b11f96a0cba12d76cb18903c0c08887e9bb
|
|
BLAKE2b-256 checksum How to use checksums |
b73f3540c05c41459d7d7ef9b86bbb79bc001501c696a9f9cc73a4ecd5a21b21
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Hatch/1.16.5 cpython/3.14.3 HTTPX/0.28.1
|