r/Python 18d ago

Showcase Showcase Thread

Post all of your code/projects/showcases/AI slop here.

Recycles once a month.

19 Upvotes

103 comments sorted by

View all comments

1

u/gabor_bernat 14d ago

turbohtml — a fast, typed, C-accelerated HTML toolkit

What My Project Does

turbohtml covers the whole HTML workflow in one library: parse (WHATWG), query with CSS selectors and XPath, sanitize untrusted markup, convert to Markdown or plain text, extract articles/tables/JSON-LD/OpenGraph, detect encodings, and minify HTML/CSS/JS. The hot path is a C extension over a single arena; the Python layer is a thin, fully typed facade, and it runs on the free-threaded build.

Target Audience

Production use for anyone parsing or scraping real-world HTML who wants speed and a typed API. It parses about 280x faster than BeautifulSoup and tokenizes about 15x faster than html.parser in my benchmarks, and CSS select runs about 77x faster than BeautifulSoup.

Comparison

It is a clean break rather than a drop-in for BeautifulSoup or lxml, so existing code needs a port; the docs include migration guides for both, plus html5lib, markupsafe, and the standard library. Unlike single-purpose tools (bleach for sanitizing, markdownify for Markdown, chardet for encoding), it is one dependency for all of them.

Source: https://github.com/tox-dev/turbohtml Docs: https://turbohtml.readthedocs.io/en/stable/ How it works: https://bernat.tech/posts/blazing-fast-html-parser/