tinyhtml
A tiny library to safely render compact HTML5 from Python expressions.
What it is and what it does
tinyhtml is a minimal Python library for building and rendering HTML5 safely. It provides a functional API where you compose HTML elements using the `h()` function, nest them by calling the result with child content, and render to a string. All text content and attributes are automatically escaped to prevent injection, with a `raw()` escape hatch for intentional unescaped HTML. The library produces compact output with no superfluous whitespace.
It integrates with Jupyter notebooks via `_repr_html_()` and works with the `__html__` protocol used by MarkupSafe and other template systems. You can write reusable templates as Python functions returning fragments, pass iterables as child elements, and use boolean or dictionary-valued attributes. The library includes mypy typings and supports Python 3.8 through 3.13.
Use it for:
- Generate HTML dynamically in web applications or scripts without string concatenation or template files.
- Build Jupyter notebook outputs programmatically with safe escaping and clean composition.
- Create email templates or HTML reports by composing fragments as Python functions.
- Integrate with Jinja2 or other template systems that support the `__html__` protocol.
- Render pandas DataFrames or other objects with `_repr_html_()` support alongside custom HTML.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Renders HTML5 safely from Python expressions using a functional API with automatic escaping and compact output.
Yes, if you need lightweight HTML generation with safety guarantees. Zero dependencies and low install friction make it easy to adopt. Dormant maintenance is acceptable for a stable, narrow-scope library—no active bugs or vulnerabilities are known. Best suited for projects that prefer functional composition over template strings and don't require advanced features like comments or inline SVG.
Install
tinyhtml on PyPI
pip
pip install tinyhtmluv
uv add tinyhtmlpoetry
poetry add tinyhtmlInstalling tinyhtml
Before you install
Low friction: pure Python wheel with no runtime dependencies. Maintenance is dormant—last release was 580 days ago, but the repository remains active with a recent commit on 2025-01-11 and no archived status.
License in practice
Dual-licensed under MIT and Apache License 2.0, both permissive. You may choose either license, giving flexibility for most projects.
Quickstart
pip install tinyhtml
from tinyhtml import h, frag
result = h("div", klass="container")(
h("h1")("Hello"),
h("p")("World")
).render()
print(result)
Verify before relying
- Whether dormant maintenance (580 days since release) affects long-term compatibility with future Python versions beyond 3.13.
- Performance characteristics when rendering very large HTML structures or deeply nested fragments.
Package facts
| License | MIT/Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | dormant — 580 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 104,254/month — #12,758 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: tinyhtml-1.3.0-py3-none-any.whl
Keywords: html, html5, vdom, functional-programming
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
html5taggerGenerates HTML5 markup programmatically using…
permissive · top 5,000 on PyPI
htbuilderhtbuilder lets you construct HTML strings using…
permissive · top 15,000 on PyPI
htpyhtpy lets you write HTML directly in Python…
permissive · top 15,000 on PyPI
htmlBuilderRender HTML by writing Python code, using…
permissive · top 15,000 on PyPI
hyperscriptHyperscript lets you generate HTML markup…
permissive · top 15,000 on PyPI
html-void-elementsProvides a list of HTML void element tag names…
copyleft · top 15,000 on PyPI
tinyhtml5Parses HTML5 documents—including malformed…
permissive · top 1,000 on PyPI
airiumAirium generates HTML from Python code using…
permissive · top 15,000 on PyPI
draftjs_exporterConverts Draft.js ContentState (a rich text…
permissive · top 5,000 on PyPI
python-liquidPython Liquid is a template engine that renders…
permissive · top 5,000 on PyPI