Skip to main content

soup5ever

A BeautifulSoup 4 tree builder backed by Rust's html5ever. Same HTML5 trees as BeautifulSoup(html, "html5lib"), 6–14x faster.

from bs4 import BeautifulSoup
import soup5ever

soup = BeautifulSoup(html, "html5ever")

Installation

pip install soup5ever

Wheels for Linux (x86_64, aarch64; glibc and musl) and macOS (arm64), one abi3 wheel per platform for CPython 3.10+. The only dependency is beautifulsoup4>=4.13; no Rust, libxml2 or html5lib needed.

Usage

Importing soup5ever registers the "html5ever" parser (also "soup5ever"). The generic features "html5" and "html" are registered at the lowest priority, so importing it doesn't change what BeautifulSoup(markup, "html5") or BeautifulSoup(markup) select.

The usual options work (from_encoding, element_classes, multi_valued_attributes, store_line_numbers, attribute_dict_class). Like html5lib, parse_only isn't supported.

Compatibility

The target is BeautifulSoup(html, "html5lib"); where html5lib and the HTML standard disagree, soup5ever follows the standard.

  • BS4's own tests for its html5lib builder: 93/93 pass.
  • html5lib-tests tree construction: 1,588/1,592 match the spec. Against html5lib the trees are identical in 1,417 cases; the other 175 are classified automatically (167 html5lib behind the spec, 4 BS4 html5lib-adapter bugs, 4 <selectedcontent> misses both share).
  • 182 targeted differential cases and ~23k fuzz inputs (triaged with Chromium): every remaining difference is an html5lib bug or listed below.

Differences from html5lib:

  • Current HTML standard where html5lib 1.1 (2020) is behind: the 2025 <select> rules, <template> in <head>, </p> in SVG/MathML, <main>/<summary>, <search>, <dialog>, ruby. See tests/corpus.py for each case.
  • BS4's html5lib adapter never applies the Noah's Ark clause (AttrList has no __eq__); soup5ever does.
  • Undeclared, valid UTF-8 bytes are decoded as UTF-8 (html5lib guesses windows-1252 without chardet). Decoding follows the WHATWG Encoding Standard, not Python's codecs.
  • Lone surrogates in a str become U+FFFD.
  • sourceline/sourcepos match html5lib for ~98.5% of elements.

Shared with html5lib: no parse_only, no Script/Stylesheet string subclasses, no <selectedcontent> cloning.

Benchmarks

BeautifulSoup(markup, parser) on an in-memory str, median of 7 rounds, 4-vCPU Linux VM, CPython 3.11:

document html5lib html5ever speedup
small page (3 KiB) 2.4 ms 250 µs 9.6x
large page (1.2 MiB) 888 ms 101 ms 8.8x
malformed tag soup 483 ms 34 ms 14.2x
deeply nested 243 ms 26 ms 9.3x
table-heavy 507 ms 69 ms 7.3x
SVG/MathML-heavy 323 ms 51 ms 6.4x

Parsing in Rust is 14–32% of soup5ever's time; the rest is BeautifulSoup's own object constructors. To reproduce:

uv pip install -e .[dev]
python benchmarks/run.py

Development

uv venv venv && source venv/bin/activate
uv pip install -e .[dev]                # builds the Rust extension
python scripts/fetch_upstream_tests.py  # BS4's builder tests + html5lib-tests
pytest

Re-run uv pip install -e .[dev] after changing Rust code.

edwh fmt && edwh lint                   # Python (ruff)
cargo fmt && cargo clippy               # Rust (lint levels in Cargo.toml)

pytest includes a 3000-input differential fuzz run; pytest --fuzz 20000 --fuzz-seed 7 runs a bigger one.

License

MIT

Metadata

Release files for soup5ever 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for soup5ever 0.1.0
File Size Uploaded
soup5ever-0.1.0.tar.gz 74.7 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for soup5ever 0.1.0
File
soup5ever-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
soup5ever-0.1.0-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details
soup5ever-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
soup5ever-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
soup5ever-0.1.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details

Total release size: 3.1 MB

Release files / soup5ever-0.1.0.tar.gz

Download URL soup5ever-0.1.0.tar.gz
Size 74.7 kB
Tags Source
SHA-256 checksum
How to use checksums
80f4db56164744261c4107fe8bc5c215668f3c00538d0672fc19c5d61a679546
BLAKE2b-256 checksum
How to use checksums
f93252daa5405cc4264bbfa947ca0adff899a5faca096fae2f23b3b3f74245cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / soup5ever-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL soup5ever-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl
Size 618.5 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
7c72dfd813d97027c36fddd5ebd404501bfc3cbab112493c4d2cab20c95d3f55
BLAKE2b-256 checksum
How to use checksums
88eb01557bb853424b3f121d703d7dbe3481826c6972de20ea4bee58fd1840b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / soup5ever-0.1.0-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL soup5ever-0.1.0-cp310-abi3-musllinux_1_2_aarch64.whl
Size 602.2 kB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
b7f93a523295de21d288206f1c944af920583d40a3be166863172d9d82d0ecfc
BLAKE2b-256 checksum
How to use checksums
f50c57bb692dad1b213916fbaa2e9496520e1500913e51c9512ac7bfc0987de6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / soup5ever-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL soup5ever-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 619.5 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
938b9f6f4ff9db8e5fb9e638cb968aec6e7657cb4829e0fd01b4d75cad758fe3
BLAKE2b-256 checksum
How to use checksums
674f175888762d7103afc885516c9148ef390fe49ad7f1736b5ee9a590b9f19c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / soup5ever-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL soup5ever-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 603.2 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
3a9ba7d5de50c189c614cdfecee6159481cb220a00ff48c13c2177451e9ef98f
BLAKE2b-256 checksum
How to use checksums
5aebd6e892114a5d61b5f1107fa42c6b15f02232dd5176d074e124c9e2e799ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / soup5ever-0.1.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL soup5ever-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
Size 559.2 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
15b94f7c1f1aaf9b9de9d8169bdbae129235e1093bee9a73272fbd5e2ea70bc3
BLAKE2b-256 checksum
How to use checksums
15a3ba8c31efca78dde423ecd5a11b87b77facac442b3b4e92d8a57033f0f4b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release history Release notifications | RSS feed

0.2.0

6 release files

This release

0.1.0 This release

6 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page