skillfed

htbuilder

A purely-functional HTML builder for Python. Think JSX rather than templates.

htbuilder v0.9.0 251.1K downloads/30d#8,595 on PyPI104
Permissive license Apache 2 DORMANT released

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 htbuilder

uv

uv add htbuilder

poetry

poetry add htbuilder

Installing 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

License :: OSI Approved :: Apache Software LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3

Tags

html string builder pythonfunctional html generationpython html templating alternativeprogrammatic html constructionhtml dom builderjsx-like python html
html-generationfunctional-programming

More HTML packages