--- id: turbohtml version: "1.6.0" license: MIT license_treatment: permissive maintenance: active --- # turbohtml — A fast, fully typed HTML toolkit for Python, powered by a C-accelerated core. License: permissive · Maintenance: active · Downloads: 99.4K/mo ## 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 above — 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 pip install turbohtml uv add turbohtml 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("

café & cake

") 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_current - Install friction: medium - Maintenance: active - Downloads: 99.4K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags fast html parser python, html parsing and querying, css selector xpath html, html to markdown conversion, html sanitization and minification, web scraping toolkit, xml parsing library, html-parsing, web-scraping, performance-critical [View on SkillFed](https://skillfed.io/packages/turbohtml) · [View on PyPI](https://pypi.org/project/turbohtml/)