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; writable on elements — el.name = 'details' renames in place, keeping attributes and children), .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.2.tar.gz (27.7 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.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (592.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

fast5ever-0.1.2-cp313-cp313-macosx_11_0_arm64.whl (525.2 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

fast5ever-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (591.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

fast5ever-0.1.2-cp312-cp312-macosx_11_0_arm64.whl (525.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

fast5ever-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (594.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

fast5ever-0.1.2-cp311-cp311-macosx_11_0_arm64.whl (530.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

fast5ever-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (594.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

fast5ever-0.1.2-cp310-cp310-macosx_11_0_arm64.whl (530.2 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: fast5ever-0.1.2.tar.gz
  • Upload date:
  • Size: 27.7 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.2.tar.gz
Algorithm Hash digest
SHA256 4a6ab524198ba0e290c96565894769c8f9df93e5e5c595db2c3c7c1b65825f83
MD5 d57ddd619a6c085efeeb217633f30467
BLAKE2b-256 1641081b135c601a2344011857caa41c6922edfcab412025b25ed083831fc329

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast5ever-0.1.2.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.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast5ever-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 316791dd1e598b92b6f59d618ce2b152b0d9ff2247e3a1e9a7a63fbfd3576477
MD5 428f1baeff1bab8642c8bfd3deb5042e
BLAKE2b-256 843d52f5083e71bcb9d2c45cf84aa71d2e3d689ea7959126611b3d8121b53269

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast5ever-0.1.2-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.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fast5ever-0.1.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 def29ef16f2872c46d2e53e90b6395f2fbafc9e5a6f3964dd6ab815ae33c16ab
MD5 092ee4a18d2102dc416814b4d127d07f
BLAKE2b-256 f5986122282e9b6cb476b0ee450f9e92567f8d3edbb3bb63ad6e3711481736a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast5ever-0.1.2-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.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast5ever-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3ddb6b9a5f07db9d8dd17ac4e0cd5b6f9f48627861761699027eaf2ae312f3d2
MD5 9f44f7a2bbfc421a8105d134aa6919f4
BLAKE2b-256 b5316ec8e622144b9b5fae010518908e267a5aef1fa70f6f371c64e1d39cc9e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast5ever-0.1.2-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.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fast5ever-0.1.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1caafd63487add0d4e9b3ac7dfdb3495ecdfa1972c42dc390afbf6f54c778230
MD5 8fe75dce7727b4c3e24265748ee9932f
BLAKE2b-256 46e02fecb142f1206ae6302333792a07e4b26d724e669309133ae089510cf5ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast5ever-0.1.2-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.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast5ever-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8dacee9cec0f08537682a3359a18b9ad4c4d2f531ed25e0620a9172070b50ffa
MD5 e78bbe78f77a5b247e64c14948e686d2
BLAKE2b-256 14470f8a0642fa74c49b632820f9dd50abc54b0dba92746a96ed0c8ccff44024

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast5ever-0.1.2-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.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fast5ever-0.1.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8c6b7f3ef21cdbef15d023b0c6da7e30416a380105a73675dcd74e8e5157cd89
MD5 5e54a1bd665c3e40cf55aff2a05ea367
BLAKE2b-256 5bac6e56b9850e3dfc98ba783dcf1cf7ad351f1d1abc2ccff722b6a5f5a77012

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast5ever-0.1.2-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.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast5ever-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3e8f9399c760f83f2164dfdf114b82b78162717fc94dc2fe2e1854aa7a17d095
MD5 784528f23c5f8a7c0eedf8230bedf7ff
BLAKE2b-256 58a0ac875598c9127b8178fc919c50ae9636c650cf25e8d4cf062b8154fb38ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast5ever-0.1.2-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.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fast5ever-0.1.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 efaac29ac9af4959d49b51eb3d4ff58f078bd3e5dda69654016a6d98d0910c8c
MD5 471275b72ef7e147be8b154da4281e36
BLAKE2b-256 4d02d7e6d2bad7107f6b95bae04579d43539d4c90c9fd6b49b1a87a35bb7ca5f

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast5ever-0.1.2-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