Skip to main content

fast5ever

WHATWG-compliant HTML parsing, mutation, and serialization for Python, powered by Rust's html5ever (the engine written for Servo).

html5ever uses the spec's algorithms but does not include the tree. fast5ever adds the missing piece, a fast arena DOM, and exposes both through a small Python API. Parsing, error recovery, and serialization all behave exactly as a browser's innerHTML does, because they are the same algorithms.

from fast5ever import parse, parse_fragment

frag = parse_fragment('<p>one<p>two')
frag.to_html()                        # '<p>one</p><p>two</p>'
[c.name for c in frag.children]       # ['p', 'p']
frag.children[0].attrs['class'] = 'lead'   # attrs is live: writes go straight to the tree

doc = parse('<!DOCTYPE html><title>t</title>hello')
doc.to_html()                         # '<!DOCTYPE html><html><head><title>t'...

API

  • parse(html) parses a complete document; parse_fragment(html, context='body') parses a fragment in a context element (pass e.g. context='tbody' to parse table rows). Both return a Document node.
  • Every node is a Document, Element, Text, Comment, or Doctype - all subclasses of Node - so kind checks are isinstance(c, Text). Shared surface: .name (tag, or #document/#text/#comment/#doctype), .children, .parent, to_html(), to_text().
  • el.attrs is a live mapping in source order: attrs['k'], attrs['k'] = v, del attrs['k'], in/len/iteration, get/keys/values/items/update/pop, == {...} against any mapping; dict(attrs) snapshots. (Non-elements read as empty and refuse writes.)
  • .text is a text or comment node's own content, writable: t.text = 'new'. template.content is a <template> element's contents as a Document.
  • Element(name, attrs=None), Text(text), and Comment(text) construct detached nodes to insert.
  • Structure: append_child, insert_before(child, reference), replace_child(new, old), detach(). Inserting a Document node splices its children in (DocumentFragment semantics), so div.replace_child(parse_fragment(markup), old) splices markup in place. Inserting a node from another tree deep-copies it; handles stay valid across all mutations.

The node API follows the WHATWG DOM's vocabulary, with a pythonic surface (real node classes, attrs as a live mapping, to_html()/to_text()) modeled on Emil Stenström's JustHTML. The parsing and serialization engine is Servo's html5ever.

Serialization is the spec's

Output spelling comes from html5ever's own serializer - the WHATWG serialization algorithm, byte-for-byte what Chrome's innerHTML builds: boolean attributes as open="", double-quoted values, voids without /, raw text unescaped inside script/style. fast5ever adds no styling options and no compatibility shims with other serializers, by design.

Parsing is also bounded Chromium-style: element nesting beyond 512 flattens at the cap (Chromium's own limit), which keeps adversarially deep input linear-time - html5ever's tree builder alone is quadratic there.

The Rust API

fast5ever is a Rust crate first (fast5ever = { git = "https://github.com/AnswerDotAI/fast5ever" }); the Python API is a thin binding over it, so the two surfaces match verb for verb. The one structural difference: Rust has no node objects - you hold the Dom (a Vec-indexed arena) and address nodes by NodeId, with node 0 (DOCUMENT) always the document. Every id stays valid for the life of the Dom, however the tree is mutated.

use fast5ever::{parse_fragment, DOCUMENT};

let mut dom = parse_fragment("<p>one<p>two", "body");
let p = dom.children(DOCUMENT)[0];
dom.set_attr(p, "class", "lead").unwrap();
let extra = parse_fragment("<b>!</b>", "body");
let extra = dom.import(&extra, DOCUMENT);   // cross-tree moves go through an explicit import
dom.append_child(p, extra).unwrap();        // a document node splices its children, as in Python
assert_eq!(dom.to_html(DOCUMENT), r#"<p class="lead">one<b>!</b></p><p>two</p>"#);

Reads mirror the Python names (children, parent, attr, to_html, to_text); writes return Result where Python raises (set_attr, set_text, append_child, insert_before, replace_child, detach); construction is create_element/create_text/create_comment (Python's Element/Text/Comment); and Rust additionally exposes NodeData matching for direct tree inspection.

Development

pip install -e .[dev]
maturin develop && pytest -q

All tests are pytest; cargo check/cargo clippy stay warning-free and need no Python (pyo3 sits behind the python feature).

Release

Release flow is: release first, then bump.

maturin develop && pytest -q
ship-rs-release
ship-bump

The GitHub workflow builds wheels on tags matching v* and publishes them to GitHub Releases and PyPI.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fast5ever-0.1.1.tar.gz (27.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

fast5ever-0.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (591.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

fast5ever-0.1.1-cp313-cp313-macosx_11_0_arm64.whl (524.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

fast5ever-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (590.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

fast5ever-0.1.1-cp312-cp312-macosx_11_0_arm64.whl (524.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

fast5ever-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (594.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

fast5ever-0.1.1-cp311-cp311-macosx_11_0_arm64.whl (529.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

fast5ever-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (594.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

fast5ever-0.1.1-cp310-cp310-macosx_11_0_arm64.whl (529.9 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file fast5ever-0.1.1.tar.gz.

File metadata

  • Download URL: fast5ever-0.1.1.tar.gz
  • Upload date:
  • Size: 27.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for fast5ever-0.1.1.tar.gz
Algorithm Hash digest
SHA256 57b017692d5643290acd22db3c0d08b003662b6a956e0e7b28fdba58e10dc080
MD5 97c23a19e74944b7f6f405a8a74b6dd4
BLAKE2b-256 d23a12e575adbc223879d616e0922b6048bcf5f5c4cd330e480fa6d1cc6bfd10

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast5ever-0.1.1.tar.gz:

Publisher: ci.yml on AnswerDotAI/fast5ever

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fast5ever-0.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast5ever-0.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5720cc33863a784a4dfebd61df2cda1cec3e8ba19d933fd0197ae7d1ea18d3bb
MD5 bf742d85a0a41642c9d7e1492ef191d3
BLAKE2b-256 3b1232c6ed70f90b24cb0c3d62b40cf1509e4c9acccc9b6d86bb8acb1bd24d86

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast5ever-0.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: ci.yml on AnswerDotAI/fast5ever

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fast5ever-0.1.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fast5ever-0.1.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d41cb819cbab33c8aaadd015f37e907437957a1c0d0b6e888f05e13208f35241
MD5 ae90c6f18041b2221995b7a2d633d936
BLAKE2b-256 eb8d05393fbf890a9ea1e8d300356bd5ed7c26e53c5c99abfe4d2c3c4281f066

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast5ever-0.1.1-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: ci.yml on AnswerDotAI/fast5ever

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fast5ever-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast5ever-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 090865e88c5fbd138e5120e6c7e69f8da727c4d7718c3f24287334dacbba53bf
MD5 484849de87818ee3158382e7f4ac21c2
BLAKE2b-256 5f2069e09c050e39aaf82cf95d64fe3f3002fbb75efe04d2123803cab920c32e

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast5ever-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: ci.yml on AnswerDotAI/fast5ever

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fast5ever-0.1.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fast5ever-0.1.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 293cdd518167a65ebf31ea23a2270127b481bb91e6ca333571fddde96cd3a7e8
MD5 0de44e9a5179aa78f4a1b03cad4f0878
BLAKE2b-256 3a8dd4e34171beca37ac3b19497e7b49edb49e203ce73c6ca4f335016fc0bb81

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast5ever-0.1.1-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: ci.yml on AnswerDotAI/fast5ever

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fast5ever-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast5ever-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2ee6084f11e54af061d4183201a98dad3ea7b1eba2923c40ba67b433d147e08f
MD5 3b0a67084d0e279602189dee6731f036
BLAKE2b-256 494057e5ca2c7e1b1a2642b6ad37075cd79f9087930cac6d16d8e6df1ac4b79b

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast5ever-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: ci.yml on AnswerDotAI/fast5ever

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fast5ever-0.1.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fast5ever-0.1.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d0509c8c9c18ad4da4b10661fbc35024fb337a95d45d41d620075f66b4c10f13
MD5 1d745bc806bd01ce967c3131e8eb01dd
BLAKE2b-256 8565d1d1931a73779ecdf151a0abaafd18e2ea89f2374a0f3288094c6c1a2c57

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast5ever-0.1.1-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: ci.yml on AnswerDotAI/fast5ever

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fast5ever-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast5ever-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 30f6b40fc725e83a68b7509b7484f8526fb08912fd22ecbd8d9e59f39fca6596
MD5 8238638d77ac848f4118e08d6c496f2f
BLAKE2b-256 451e159e43e65bbe8bf01ed7f007ab5555c7bdd0bf1a7631d259222be17d598e

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast5ever-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: ci.yml on AnswerDotAI/fast5ever

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fast5ever-0.1.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fast5ever-0.1.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cc90a4f9ce96332afc4fb76ed028626b2def343a3ffd47b170c9ee9c53586af4
MD5 03131487628388e3e22bd8447e347545
BLAKE2b-256 eb19b457e58da8f2912ff4b4f9a2af69554c6e9d408817ae9e4ff386b8428dab

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast5ever-0.1.1-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: ci.yml on AnswerDotAI/fast5ever

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page