Migrating to turbohtml¶
turbohtml replaces the HTML libraries it benchmarks against. None is API-compatible, so porting is a translation: turbohtml uses one name per concept and a typed shape where those libraries spread the work across aliases, methods, and treebuilder choices. This page maps each library to turbohtml; BeautifulSoup gets the deepest treatment because it shares the most surface.
The guides are grouped by the turbohtml namespace that replaces each library – parse & DOM, detect, query, clean, convert, extract, build, serialize, the same order the Reference and How-to guides use – so a library that spans namespaces sits under the one it maps to most directly. Within each group they are ordered by adoption, most to least monthly PyPI downloads, from the pepy.tech badge on each row; where two libraries share a download tier the order follows that tier rather than a precise count. The all-time totals and each library’s documentation sit alongside for context.
Parse & DOM¶
These libraries parse HTML into a document tree. turbohtml.parse() builds the tree a browser would, so malformed
input recovers the WHATWG way, and every node shares the navigation, query, and mutation surface in
Nodes.
# |
Library |
Docs |
Monthly downloads |
Total downloads |
|---|---|---|---|---|
1 |
||||
2 |
||||
3 |
||||
4 |
||||
5 |
||||
6 |
||||
7 |
||||
8 |
Bundled with Python |
– |
||
9 |
JavaScript (npm) |
– |
||
10 |
JavaScript (npm) |
– |
||
11 |
Rust / WASM |
– |
parse5 is the reference JavaScript WHATWG parser rather than a Python library; its guide is a cross-language reference
for porting a parse5 pipeline – and its sourceCodeLocationInfo model in particular – onto turbohtml. jsdom is the
reference JavaScript DOM built on parse5; its guide maps the DOM traversal (TreeWalker, NodeIterator) and range
(Range, StaticRange) APIs onto turbohtml’s. lol-html is Cloudflare’s Rust streaming HTML rewriter; its guide
maps its DOM-less HTMLRewriter and Element edit API onto turbohtml.rewrite.rewrite().
Detect¶
turbohtml.detect.detect() sniffs the character encoding of raw bytes with the same C pipeline
turbohtml.parse() runs – the WHATWG sniff, then Firefox’s chardetng scoring – so it answers what these libraries
answer, with the result a browser would pick.
Query¶
These libraries select nodes with CSS or XPath, or read the CSS Object Model. turbohtml matches CSS selectors with
turbohtml.Node.select(), evaluates XPath 1.0 with turbohtml.Node.xpath(), exposes a soupsieve-shaped
matching surface in Query, and resolves the CSS cascade to a computed style in
CSSOM.
Clean¶
These libraries scrub, sanitize, or shrink markup. turbohtml.clean sanitizes against an allowlist, autolinks bare
URLs, and minifies HTML with minify(), CSS with minify_css(), and
JavaScript with minify_js() – every minifier value-safe.
Convert¶
turbohtml.convert.css_to_xpath() translates a CSS selector into the equivalent XPath 1.0 expression, the job
cssselect does for lxml, parsel, and pyquery, so a system that speaks only XPath can run a CSS selector.
Extract¶
These libraries pull the article, its metadata, or embedded structured data out of a page.
turbohtml.Node.main_content() isolates the article body, turbohtml.Element.records() reads a table into
records, and turbohtml.Document.structured_data() collects JSON-LD, Microdata, OpenGraph, and RDFa.
Build¶
These libraries construct HTML from Python. turbohtml.build.E builds a real element tree that queries, edits,
and serializes like a parsed one.
Serialize¶
These libraries render a tree back out – as escaped HTML, Markdown, or plain text. turbohtml.escape() and the
turbohtml.migration.markupsafe drop-in match markupsafe byte for byte, turbohtml.Node.to_markdown() emits
GitHub-Flavored Markdown, and turbohtml.Node.to_text() extracts rendered text.