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

beautifulsoup

docs

beautifulsoup4 monthly downloads beautifulsoup4 total downloads

2

lxml

docs

lxml monthly downloads lxml total downloads

3

html5lib

docs

html5lib monthly downloads html5lib total downloads

4

selectolax

docs

selectolax monthly downloads selectolax total downloads

5

resiliparse

docs

resiliparse monthly downloads resiliparse total downloads

6

mechanicalsoup

docs

MechanicalSoup monthly downloads MechanicalSoup total downloads

7

html5-parser

docs

html5-parser monthly downloads html5-parser total downloads

8

stdlib

docs

Bundled with Python

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.

#

Library

Docs

Monthly downloads

Total downloads

1

charset-normalizer

docs

charset-normalizer monthly downloads charset-normalizer total downloads

2

chardet

docs

chardet monthly downloads chardet total downloads

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.

#

Library

Docs

Monthly downloads

Total downloads

1

soupsieve

docs

soupsieve monthly downloads soupsieve total downloads

2

parsel

docs

parsel monthly downloads parsel total downloads

3

pyquery

docs

pyquery monthly downloads pyquery total downloads

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.

#

Library

Docs

Monthly downloads

Total downloads

1

cssselect

docs

cssselect monthly downloads cssselect total downloads

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.

#

Library

Docs

Monthly downloads

Total downloads

1

markupsafe

docs

markupsafe monthly downloads markupsafe total downloads

2

markdownify

docs

markdownify monthly downloads markdownify total downloads

3

html2text

docs

html2text monthly downloads html2text total downloads

4

inscriptis

docs

inscriptis monthly downloads inscriptis total downloads

5

html-text

docs

html-text monthly downloads html-text total downloads