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.
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. turbohtml matches CSS selectors with turbohtml.Node.select(),
evaluates XPath 1.0 with turbohtml.Node.xpath(), and exposes a soupsieve-shaped matching surface in
Query.
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.