turbohtml
A fast, fully typed HTML toolkit for Python, powered by a C-accelerated core.
What it is and what it does
turbohtml is a high-performance HTML and XML processing library that combines a C-accelerated parser and query engine with a fully-typed Python interface. It handles tokenization, parsing, querying via CSS selectors and XPath, serialization to HTML or markdown, form extraction, sanitization, minification, and rewriting—all without native dependencies beyond the pre-built wheels. The library models the DOM according to the WHATWG standard, exposing child nodes as indexable items and attributes through a dedicated `.attrs` interface.
The package is designed for web scraping, content extraction, and HTML transformation workflows. Common use cases include extracting article text and converting it to markdown for language models, sanitizing untrusted HTML, minifying markup, detecting character encodings, and building or editing HTML programmatically. It is not a drop-in replacement for BeautifulSoup or lxml; the fact sheet provides migration guides for 65 libraries, but you will need to adapt your code to turbohtml's API.
Use it for:
- Extract main article content from a web page and convert it to markdown for processing by a language model.
- Sanitize user-submitted HTML to remove scripts and dangerous attributes while preserving safe markup.
- Parse and minify HTML, CSS, and JavaScript in a single streaming pass without building an intermediate tree.
- Query HTML documents using CSS selectors or XPath and extract structured data (tables, JSON-LD, microdata).
- Detect character encoding of HTML documents and parse them with automatic encoding sniffing.
- Build or edit HTML programmatically using Element constructors and live attribute manipulation.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Parse, query, edit, and serialize HTML and XML documents with a C-accelerated core, supporting CSS selectors, XPath, markdown export, sanitization, and form extraction.
Yes. turbohtml is actively maintained, carries no security vulnerabilities, uses a permissive MIT license, and installs without compilation on modern Python versions (3.10–3.15). It is well-suited for performance-critical HTML processing, web scraping, and content extraction. The main caveat is that it is not API-compatible with BeautifulSoup or lxml, so adoption requires rewriting existing code—but migration guides are provided for 65 libraries. Install it if you need fast, typed HTML handling and are willing to learn its API.
Install
turbohtml on PyPI
pip
pip install turbohtmluv
uv add turbohtmlpoetry
poetry add turbohtmlInstalling turbohtml
Before you install
Wheels are pre-built for CPython 3.10–3.15 across major platforms (macOS, Linux, Windows, including free-threading variants), so installation requires no compilation. Active maintenance with a release 3 days old.
License in practice
MIT license permits commercial and private use with minimal restrictions; you may use, modify, and distribute turbohtml freely provided you include the license notice.
Quickstart
pip install turbohtml
import turbohtml
from turbohtml import Html, Formatter
doc = turbohtml.parse("<p>café & cake</p>")
print(doc.select_one("p").text) # café & cake
print(doc.select_one("p").serialize(Html(formatter=Formatter.NAMED_ENTITIES)))
Requires Python 3.10 or later.
Verify before relying
- Whether the C-accelerated core and free-threading support deliver the claimed 2–5× parsing speedup and 9–15× tokenization speedup in typical production workloads.
- Whether the WHATWG DOM model (indexing children via node[i], accessing attributes via node.attrs) is sufficiently intuitive for developers migrating from BeautifulSoup or lxml.
- Whether the 65 migration shims cover the specific libraries and patterns your codebase relies on.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 3 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 99,408/month — #13,024 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: turbohtml-1.6.0-cp310-cp310-macosx_11_0_arm64.whl; turbohtml-1.6.0-cp310-cp310-manylinux_2_28_aarch64.whl; turbohtml-1.6.0-cp310-cp310-manylinux_2_28_x86_64.whl; turbohtml-1.6.0-cp310-cp310-musllinux_1_2_aarch64.whl; turbohtml-1.6.0-cp310-cp310-musllinux_1_2_x86_64.whl; turbohtml-1.6.0-cp310-cp310-win_amd64.whl; turbohtml-1.6.0-cp311-cp311-macosx_11_0_arm64.whl; turbohtml-1.6.0-cp311-cp311-manylinux_2_28_aarch64.whl; turbohtml-1.6.0-cp311-cp311-manylinux_2_28_x86_64.whl; turbohtml-1.6.0-cp311-cp311-musllinux_1_2_aarch64.whl; turbohtml-1.6.0-cp311-cp311-musllinux_1_2_x86_64.whl; turbohtml-1.6.0-cp311-cp311-win_amd64.whl; turbohtml-1.6.0-cp312-cp312-macosx_11_0_arm64.whl; turbohtml-1.6.0-cp312-cp312-manylinux_2_28_aarch64.whl; turbohtml-1.6.0-cp312-cp312-manylinux_2_28_x86_64.whl; turbohtml-1.6.0-cp312-cp312-musllinux_1_2_aarch64.whl; turbohtml-1.6.0-cp312-cp312-musllinux_1_2_x86_64.whl; turbohtml-1.6.0-cp312-cp312-win_amd64.whl; turbohtml-1.6.0-cp313-cp313-macosx_11_0_arm64.whl; turbohtml-1.6.0-cp313-cp313-manylinux_2_28_aarch64.whl
Keywords: css-selector, encoding-detection, escape, html, html5, markdown, minify, parser, sanitize, scraping, unescape, xml, xpath
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
cssselectcssselect parses CSS3 selectors and translates…
permissive · top 1,000 on PyPI
w3libw3lib provides utility functions for common web…
permissive · top 5,000 on PyPI
parselParsel extracts data from HTML, JSON, and XML…
permissive · top 5,000 on PyPI
pyquerypyquery lets you query and manipulate XML and…
permissive · top 5,000 on PyPI
selectolaxselectolax is a fast HTML5 parser with CSS…
permissive · top 5,000 on PyPI
tinyhtml5Parses HTML5 documents—including malformed…
permissive · top 1,000 on PyPI
beautifulsoup4Beautiful Soup parses HTML and XML documents…
permissive · top 100 on PyPI
saxoncheSaxonC-HE is a Python wrapper for Saxon, an XML…
unclear · top 5,000 on PyPI
BeautifulSoupBeautiful Soup parses HTML and XML documents…
permissive · top 15,000 on PyPI
html5libhtml5lib parses HTML documents into a tree…
permissive · top 1,000 on PyPI