skillfed

turbohtml

A fast, fully typed HTML toolkit for Python, powered by a C-accelerated core.

turbohtml v1.6.0 99.4K downloads/30d#13,024 on PyPI20
Permissive license MIT Active released

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 turbohtml

uv

uv add turbohtml

poetry

poetry add turbohtml

Installing 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é &amp; 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.15Programming Language :: Python :: Free Threading :: 1 - UnstableProgramming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: InternetTopic :: Software Development :: LibrariesTopic :: Text Processing :: Markup :: HTMLTopic :: Text Processing :: Markup :: MarkdownTopic :: Text Processing :: Markup :: XMLTyping :: Typed

Tags

fast html parser pythonhtml parsing and queryingcss selector xpath htmlhtml to markdown conversionhtml sanitization and minificationweb scraping toolkitxml parsing library
html-parsingweb-scrapingperformance-critical

More Libraries packages