The parsing foundation for the web.
Parsec reads HTML, CSS, JavaScript, XML, URLs and text encodings the way the standards say a browser should, and hands you the tree. It's written in Rust, split into crates you take one at a time, and it runs from Python, JavaScript and C as well.
Version 0.3.1, Apache-2.0.
What you wrote
<title>Shop</title>
<p class=lead>Hello <b>world</p>
<p>againWhat Parsec built
<html>
<head>
<title>
"Shop"
"\n"
<body>
<p class="lead">
"Hello "
<b>
"world"
<b>
"\n"
<p>
"again"What it noticed on the way
1:1expected-doctype-but-got-start-tag2:29unexpected-end-tag3:9expected-closing-tag-but-got-eof
<b>, so it carries into the next paragraph, exactly as it does in every browser.Six parsers, each in its own crate
Want CSS but not HTML? Take parsec-web-css with its default features off and you won't compile an HTML tokenizer. Every number below is what Parsec's CI requires on its main branch today, read from the baseline when this page was built.
| Parses | What you get | Crate | Checked against |
|---|---|---|---|
| HTML | The HTML Standard’s tokenizer and tree builder, CSS selectors, XPath 1.0, serializing and editing the tree. | parsec-web-core | html5lib tree construction: 3,898 pass, none fail |
| CSS | Tokenizing and parsing stylesheets, typed values for every property, media queries and the cascade. | parsec-web-css | web-platform-tests CSS parsing: 14,758 pass, 135 don't yet |
| JavaScript | ECMAScript 2025 scripts and modules to a tree with spans, ESTree JSON, scopes, and page state read without running anything. | parsec-js | test262, parsing: 52,782 pass, none fail |
| XML | XML 1.0 with namespaces, not validating, with a span on every node and XPath over the result. | parsec-xml | W3C XML conformance: 1,915 pass, none fail |
| URL | The WHATWG URL Standard: parsing, setters, origins and IDNA, as browsers resolve links. | parsec-url | web-platform-tests URL parsing: 904 pass, none fail |
| Encoding | Finding a page’s encoding the way a browser does, and decoding it, from whole bytes or a stream. | parsec-web-encoding | web-platform-tests legacy multi-byte: 62,352 pass, none fail |
Fast is a result. The numbers are how you check it.
Standards
679,730 tests pass across 35 conformance suites, from html5lib and test262 to the web-platform-tests. 30 of those suites pass every test they run. The 5 that don't are still in the baseline, so a regression fails CI and a fix has to raise the count:
css-parsing-tests: 3,270 of 8,366html5lib-tree-construction-error-counts: 165 of 1,967wpt-cascade: 131 of 1,474wpt-computed-values: 755 of 12,111wpt-css-parsing: 135 of 14,893
Speed
- Parsing 13 real pages, 24.36 MB
- 370 MB/s, against 242 for Lexbor's C and 82 for html5ever, 1.53 times Lexbor's speed
- 32 CSS selectors over those pages
- 226 ms in all, where Lexbor takes 728
- JavaScript, 11.58 MB of bundles and inline scripts
- 380 MB/s, against 363 for oxc and 147 for swc; oxc is still ahead on the smallest inline scripts
One machine's numbers: an Apple M2 Max (12 cores, 32 GB), macOS 26.7, on 15 November 2026 for HTML and selectors and 28 November 2026 for JavaScript. The Benchmarks page has every row, the corpus and the commands to run it yourself in about five minutes.
Separate trees, shared plumbing
HTML and XML look alike and parse nothing alike, so they don't share a tree builder. Each language keeps its own grammar, its own tree and its own error handling. What they share is small: spans, line indexes, diagnostics and limits, in a crate that depends on nothing. CI checks that every crate reaches only what's in its row here, and fails the build when one doesn't.
| Crate | For | Reaches |
|---|---|---|
parsec-base | spans, line indexes, diagnostics and limits | nothing at all |
parsec-web-core | the HTML parser and its tree | no other Parsec crate |
parsec-url | URLs | no other Parsec crate |
parsec-js | JavaScript | parsec-base |
parsec-xml | XML | parsec-base, and parsec-xpath with the xpath feature |
parsec-xpath | XPath 1.0 | parsec-web-core with the html feature |
parsec-web-css | CSS | parsec-web-core with the cascade feature |
parsec-web-encoding | encodings | parsec-web-core with the parse feature |
parsec-web | the one most people install | core, CSS, encoding, URL and XPath together |
Tested against the web, not only the specs
Spec suites tell you a parser is right by the standard. They can't tell you it survives the pages people actually crawl. That's what Netweir is for. It's the crawling and extraction framework the HTML parser was first written for, and it now builds on Parsec's crates from crates.io like anyone else.
Every Monday, Netweir's CI fetches 300 pages from a pinned list of 2,709 production URLs, a different slice each week, and parses each one with Parsec and with html5ever. If Parsec panics, hangs, or builds a tree html5ever disagrees with, the run fails. The list mixes the top sites' home pages with Wikipedia in 33 languages, docs, news, forums, shops, government sites and pages in legacy encodings.
Add it in one line
- Rust
cargo add parsec-web0.3.1 on crates.io - Python
pip install parsec-web0.3.1 on PyPI - JavaScript
npm install parsec-web0.3.1 on npm - Ca header and a static library for each platformon the release page
The crate is parsec-web and the library inside it is parsec, so Rust code says use parsec::…. In Python the module is parsec_html.
let doc = parsec::parse("<title>Shop</title><p>Hello", false);
assert_eq!(
doc.inner_html(doc.root()),
"<html><head><title>Shop</title></head><body><p>Hello</p></body></html>"
);No <html>, no <body>, an unclosed <p>. Parsec fixes all three the way a browser would, because the HTML Standard says how to recover from every mistake and it follows that. The getting started guide goes from here to selectors, edits and writing the page back out.
Build on it, or help build it
Found a page Parsec gets wrong? That's the most useful thing you can send me, along with a benchmark run on your own machine or a fix for a test that doesn't pass yet.