dominate
Dominate is a Python library for creating and manipulating HTML documents using an elegant DOM API.
What it is and what it does
Dominate provides a Pythonic way to construct HTML by treating each HTML element as a Python class. You instantiate tags, nest them using context managers or method chaining, set attributes via keyword arguments or dictionary-like access, and render the result to a string. The library eliminates the need to write raw HTML or learn a separate templating syntax—instead, you write pure Python code that reads naturally and lets you use Python's full feature set (loops, conditionals, functions) to generate markup.
The package is lightweight with zero runtime dependencies and works across Python 3.7 through 3.12 as well as PyPy. It supports both human-readable pretty-printing and compact rendering, handles HTML5 data attributes, provides shortcuts for reserved keywords like `class` and `for`, and allows you to build reusable widget functions using decorators. It's commonly used for server-side HTML generation, dynamic page building, and creating HTML-based reports or documentation.
Use it for:
- Generate HTML pages dynamically in web frameworks without a separate template engine.
- Build reusable HTML components as decorated Python functions for modular page construction.
- Create HTML reports or documentation programmatically from Python data structures.
- Generate email templates or HTML content in backend services without string concatenation.
- Prototype or test HTML structures in Python without writing raw markup strings.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Dominate is a Python library for writing HTML documents programmatically using a DOM API, letting you generate HTML pages in pure Python without learning a template language.
Yes. Dominate is a mature, actively maintained library with no dependencies, broad Python version support, and no known vulnerabilities. The copyleft license (LGPL-3.0) requires source disclosure if you distribute the library itself, but poses no barrier for internal or open-source use. Install it if you prefer writing HTML in Python over templates or string manipulation.
Install
dominate on PyPI
pip
pip install dominateuv
uv add dominatepoetry
poetry add dominateInstalling dominate
Before you install
Installation is straightforward with no runtime dependencies. The package is actively maintained with recent commits and a stable release history since 2013, supporting current Python versions (3.7–3.12 and PyPy).
License in practice
Dominate is licensed under LGPL-3.0-or-newer (copyleft). If you distribute software that links or bundles this library, you must make your source code available under compatible terms.
Quickstart
pip install dominate
import dominate
from dominate.tags import div, p, html, body
doc = dominate.document(title='Example')
with doc:
with div(id='content'):
p('Hello, World!')
print(doc)
Verify before relying
- Performance characteristics when generating very large HTML documents or deeply nested structures.
- Whether the library supports HTML5 semantic elements beyond standard tag coverage.
Package facts
| License | LGPL-3.0-or-newer (copyleft) |
| Python support | supports the current Python release (>=3.4) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 964 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,148,985/month — #3,253 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: dominate-2.9.1-py2.py3-none-any.whl
Keywords: framework, templating, template, html, xhtml, python, html5
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
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
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
airiumAirium generates HTML from Python code using…
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
braqBraq is a Python library for parsing and…
permissive · top 15,000 on PyPI