A fast, fully typed HTML toolkit for Python, powered by a C-accelerated core.
Actively maintained. Last release 7 days ago, commits in 25 of the last 26 weeks. A safe choice.
pip install turbohtmlturbohtml
A fast, fully typed HTML toolkit for Python with a C-accelerated core: tokenize, parse, query, edit, serialize, and extract HTML several times faster than the pure-Python alternatives, with free-threading support. The hot path is C; a thin typed facade is the only Python you touch. It is not a drop-in for the libraries it replaces.
Install
$ pip install turbohtml
Wheels ship per interpreter for CPython 3.11–3.15 (including free-threading), so there is nothing to compile.
Quickstart
Parse a document, query it with a CSS selector, and serialize a node back to HTML with the escaping you choose:
import turbohtml
from turbohtml import Formatter, Html
doc = turbohtml.parse("<article><h1>Tea</h1><p class=note>café & cake</p></article>")
print([h.text for h in doc.find_all("h1")]) # ['Tea']
print(doc.select_one("p.note").text) # café & cake
print(doc.select_one("p").serialize(Html(formatter=Formatter.NAMED_ENTITIES)))
# <p class="note">café & cake</p>
Each renderer takes one configuration object — Html for serialize/encode, Markdown for to_markdown, and
PlainText for to_text/ — instead of a long keyword list, so options stay grouped and
discoverable.