htbuilder
A purely-functional HTML builder for Python. Think JSX rather than templates.
What it is and what it does
htbuilder is a lightweight HTML string generator that replaces template languages with pure Python function calls. Instead of writing HTML templates or concatenating strings, you import tag names (div, span, ul, etc.) as functions and call them with content and attributes as arguments. The package supports multiple syntaxes—positional arguments, keyword arguments, chained calls with parentheses, or bracket notation—so you can choose the style that reads most naturally to you.
The core value is that HTML generation becomes just Python: you can use loops, conditionals, and variables directly in your markup without template syntax. It also provides helper functions for common patterns like building style strings, class lists, and CSS units. With no runtime dependencies and a permissive license, it's a minimal, self-contained tool for scenarios where you need to generate HTML programmatically rather than render from a template.
Use it for:
- Generate HTML email bodies or reports dynamically in Python without learning a template language.
- Build web scraper output or data-driven HTML documents where structure depends on runtime conditions.
- Construct HTML fragments in web frameworks (e.g., Streamlit, FastAPI) where inline Python markup is clearer than templates.
- Programmatically create test fixtures or mock HTML responses in unit tests.
- Generate static site content or documentation where HTML structure is computed from data structures.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
htbuilder lets you construct HTML strings using Python function calls and operators instead of template syntax, supporting attributes, nested elements, and conditional rendering through pure Python code.
Yes, if you prefer writing HTML in Python and don't need frequent updates. The package is stable, has no security vulnerabilities, and solves a real problem for developers who dislike template syntax. The dormant maintenance and source-only distribution are minor friction, but the zero runtime dependencies and permissive license make it low-risk for projects that can tolerate infrequent upstream changes.
Install
htbuilder on PyPI
pip
pip install htbuilderuv
uv add htbuilderpoetry
poetry add htbuilderInstalling htbuilder
Before you install
Installation friction is high—the package ships as a source distribution only. Maintenance is dormant: the last commit was 2025-01-09, but the prior release cycle was 582 days earlier, suggesting infrequent updates. The repository remains active (not archived) with 104 stars.
License in practice
Licensed under Apache 2 (permissive), which allows commercial and private use with minimal restrictions. No notable licensing constraints for most use cases.
Quickstart
pip install htbuilder
from htbuilder import div, ul, li
dom = div(id='container')[
ul(_class='items')[
li('item 1'),
li('item 2'),
]
]
print(dom)
Requires Python 3.7 or later.
Verify before relying
- Whether high install friction (source-only distribution) impacts real-world adoption or if wheels are available through alternative channels.
- Performance characteristics when building large or deeply nested HTML structures.
- Whether dormant maintenance status affects compatibility with newer Python versions beyond 3.7.
Package facts
| License | Apache 2 (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | high — source build required |
| Runtime dependencies | none |
| Maintenance | dormant — 582 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 251,139/month — #8,595 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: htbuilder-0.9.0.tar.gz
Tags
More HTML packages
MarkupSafe provides a text object that escapes…
permissive · top 100 on PyPI
Jinja2Jinja2 is a templating engine that renders…
permissive · top 100 on PyPI
beautifulsoup4Beautiful Soup parses HTML and XML documents…
permissive · top 100 on PyPI
lxmllxml provides Python bindings to libxml2 and…
permissive · top 1,000 on PyPI
docutilsDocutils converts plaintext documentation in…
unclear · top 1,000 on PyPI
MarkdownConverts Markdown text to HTML using a Python…
permissive · top 1,000 on PyPI
htpyhtpy lets you write HTML directly in Python…
permissive · top 15,000 on PyPI
hyperscriptHyperscript lets you generate HTML markup…
permissive · top 15,000 on PyPI
htmlBuilderRender HTML by writing Python code, using…
permissive · top 15,000 on PyPI
tinyhtmlRenders HTML5 safely from Python expressions…
permissive · top 15,000 on PyPI
dominateDominate is a Python library for writing HTML…
copyleft · top 5,000 on PyPI
html5taggerGenerates HTML5 markup programmatically using…
permissive · top 5,000 on PyPI
htaghtag is a Python GUI toolkit for building web,…
permissive · top 15,000 on PyPI
brancaBranca generates HTML and JavaScript pages from…
permissive · top 5,000 on PyPI
meld3meld3 is an HTML/XML templating system that…
permissive · top 15,000 on PyPI
htmltoolshtmltools provides Python functions to…
permissive · top 5,000 on PyPI