skillfed

dominate

Dominate is a Python library for creating and manipulating HTML documents using an elegant DOM API.

dominate v2.9.1 2.1M downloads/30d#3,253 on PyPI1,826
Copyleft license LGPL-3.0-or-newer Active released

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 dominate

uv

uv add dominate

poetry

poetry add dominate

Installing 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

Intended Audience :: DevelopersLicense :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)Operating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: PyPyTopic :: Internet :: WWW/HTTP :: Dynamic ContentTopic :: Software Development :: Libraries :: Python ModulesTopic :: Text Processing :: Markup :: HTML

Tags

python html generationhtml dom apigenerate html in pythonhtml templating without templatespython html builderprogrammatic html creationhtml document generation
html-generationtemplating-alternative

More Python Modules packages