htpy
htpy - HTML in Python
Decision gist · record as of 2026-08-14
Yes. htpy is actively maintained, has low install friction, carries no known vulnerabilities, and uses a permissive MIT license. It is well-suited if you prefer writing HTML in Python over templates and want static typing and debugging support. Not necessary if you are already satisfied with your templating approach or need Python versions below 3.10.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.10 or later.
- Low friction: pure Python wheel with only two lightweight runtime dependencies (markupsafe, typing_extensions).
- Active maintenance with recent release 84 days ago and 477 repository stars.
License · maintenance · safety
MIT (permissive) — MIT license permits unrestricted use, modification, and distribution in both open and closed projects with minimal restrictions.
last release 2026-05-22 (84 days) · last repo commit 2026-05-22 · 477 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 206,954 downloads/mo, #9,561 on PyPI
Alternatives
Verify before relying
pip install htpy
from htpy import html, head, body, title, h1, ul, li
result = html[
head[title["Example"]],
body[h1["Hello"], ul[(li[item] for item in ["one", "two"])]]
]- Whether the package's async support integrates seamlessly with specific ASGI frameworks beyond Starlette and FastAPI.
- Performance characteristics when rendering large or deeply nested HTML structures.
- Compatibility with type checkers other than mypy and pyright.
What it is and what it does
htpy is a Python library for generating HTML without templates. Instead of writing HTML strings or using a template language, you define HTML elements and structure using Python syntax—nesting child elements with brackets, passing attributes as function arguments, and composing components as regular Python functions or variables. It relies on markupsafe for safe HTML escaping and typing_extensions for type hints.
The library is designed to work with any Python web framework (Django, Flask, etc.) and supports async rendering for ASGI frameworks. Because HTML is just Python code, you can use static type checking with mypy or pyright, debug with standard Python debuggers, and leverage Python's full feature set—functions, classes, comprehensions, conditionals—to organize and reuse components. It was created to avoid the friction of template languages while maintaining the familiarity of Python development.
Use it for
- Build server-rendered HTML components for htmx-driven interfaces without switching to a template language.
- Generate complex, nested HTML structures in Flask or Django views using Python functions and comprehensions.
- Type-check your HTML generation code with mypy or pyright to catch structural errors early.
- Render HTML asynchronously in FastAPI or Starlette applications with full async/await support.
- Create reusable HTML components as Python functions or classes that compose like regular code.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
htpy is actively maintained, has low install friction, carries no known vulnerabilities, and uses a permissive MIT license. It is well-suited if you prefer writing HTML in Python over templates and want static typing and debugging support. Not necessary if you are already satisfied with your templating approach or need Python versions below 3.10.
Install
htpy on PyPI
Before you install
Low friction: pure Python wheel with only two lightweight runtime dependencies (markupsafe, typing_extensions). Active maintenance with recent release 84 days ago and 477 repository stars.
Requires Python 3.10 or later.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open and closed projects with minimal restrictions.
Quickstart
pip install htpy
from htpy import html, head, body, title, h1, ul, li
result = html[
head[title["Example"]],
body[h1["Hello"], ul[(li[item] for item in ["one", "two"])]]
]
Verify before relying
- Whether the package's async support integrates seamlessly with specific ASGI frameworks beyond Starlette and FastAPI.
- Performance characteristics when rendering large or deeply nested HTML structures.
- Compatibility with type checkers other than mypy and pyright.
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release >=3.10 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 2 packagesmarkupsafetyping_extensions |
| Maintenance | Actively maintained 84 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 206,954 / month, #9,561 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 4 - BetaIntended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: Python :: 3Topic :: Text Processing :: Markup :: HTMLTyping :: Typed |
Evidence: htpy-26.5.1-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “write HTML with Python code”
- htpyhtpy lets you write HTML directly in Python using bracket syntax and…
- PlimPlim translates a concise Ruby-inspired template syntax into HTML and…
- airiumAirium generates HTML from Python code using indentation and context…
Give your agent the search over MCP, or paste the wish link into any chat.
More HTML packages
MarkupSafe provides a text object that escapes special characters so untrusted strings can be safely embedded in HTML and XML without injection attacks.
Jinja2 is a templating engine that renders dynamic content by combining templates with Python-like syntax and data, supporting template inheritance, macros, autoescaping, and sandboxed execution.
Beautiful Soup parses HTML and XML documents into a navigable tree, providing Pythonic methods to search, iterate, and modify the parsed content.
Install it if you need to parse or extract data from markup documents.
lxml provides Python bindings to libxml2 and libxslt, enabling parsing, validation, and transformation of XML and HTML documents through an ElementTree-compatible API with support for XPath, XSLT, and schema validation.
Install it if you need robust XML/HTML parsing, validation, or transformation; avoid it only if you must stay pure-Python and can accept slower performance.
Docutils converts plaintext documentation in reStructuredText format into multiple output formats including HTML, XML, and LaTeX using a modular processing system.
Converts Markdown text to HTML using a Python implementation of John Gruber's Markdown specification, with support for extensions.
Install it if you need to parse Markdown in Python.
See also htbuilder · tinyhtml · textile · html5tagger · dominate · python-fasthtml · htmlBuilder · html-text · tabulate · hyperscript