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: tag-push (CI publishes), then the version bump, all in one command.

maturin develop && pytest -q
ship-release

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.3.tar.gz (27.9 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.3-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.3-cp313-cp313-macosx_11_0_arm64.whl (525.2 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

fast5ever-0.1.3-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.3-cp312-cp312-macosx_11_0_arm64.whl (525.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

fast5ever-0.1.3-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.3-cp311-cp311-macosx_11_0_arm64.whl (530.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

fast5ever-0.1.3-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.3-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.3.tar.gz.

File metadata

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

File hashes

Hashes for fast5ever-0.1.3.tar.gz
Algorithm Hash digest
SHA256 caca4cdbf3aa68da117a700dc36588237e9a02115b1c472ef1b1736da5dec416
MD5 260c4065850e52b6b63d8b0a6a83d8c9
BLAKE2b-256 4d50039e949d12fe056a44ee5f8a903000deee16368100fe41910f7b893f1a4f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fast5ever-0.1.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 57a6dc8eff2b3b9e28fbd04e44f5917e5e8f60b3b69a1d582765210d179b2939
MD5 475781d6f79b1be19993a4da04e2c040
BLAKE2b-256 2df37c7955f00cb0484616ed3cd871da0516a5a7cd3d2e492012475c7925d79e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fast5ever-0.1.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 577bb146de5e8d888871d2e73c00e6ca3bd2fd567f3ac416fe69d81a4b298413
MD5 cb2436df317212ed08c679eebaa3be04
BLAKE2b-256 895e6725460e445875d3f4a1ea38b4ff6aa01aac6f25e42f24ac0254ac7df1b9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fast5ever-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9ea6d354684b6f9b7f7776c820f2cb7f8259546552362fdc91b43811ab63dc36
MD5 3c95f40f1aead9d2154d680039282e99
BLAKE2b-256 439b784fc6f40206ccfe54b742a1e841c294e615cf24f62cc7f225fa28e9aeef

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fast5ever-0.1.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cf742db6648b20520c363da7efac0682735622585536adc6ab85668563727ee2
MD5 1a0ec8e322d2c8e595b471140cfa09a2
BLAKE2b-256 085ec699971d4296ad3be8450e5afb6c97903b8bb5107a655e28698b2721233f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fast5ever-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 65aaea4caf85e8ecf3f93f4dbba959c2c401406ee5939a43451ef843a7860a29
MD5 f35843a69c73a20b6ec4c2ff792ba02b
BLAKE2b-256 bcaa315f5bdf81970ca2f3e1073e2508134ba695d977f3e5002015c0d8d0894e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fast5ever-0.1.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7c9ac11fda8eb89f27b2c61941abf742ad548d9e0472f328a2ab66fcb8e7e4a2
MD5 34c185498df0eebb7668e5843a08b6cb
BLAKE2b-256 388ccf06aa36dc9380ed0dc006d9bcd59a5dc5b6205732e8865be716ef32db2e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fast5ever-0.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 75cf07958384882e73e96b5586c1d228439519393739f0163bdd514c05a0911c
MD5 c7931d21ed41471a8dafdb49f7d77963
BLAKE2b-256 4f8f2cbf11aabd39c1778e0375968ebb1b3856a52798fc7116591e302a848263

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fast5ever-0.1.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7902ab4b1445cbf07dd5f16267946e59633ae368ccd0281045744877037e0fa7
MD5 91b974200a102c8f76af77eb4d627880
BLAKE2b-256 9e886754ca8e4761fcd444925119e431524359c333e6256d17f503a37318d990

See more details on using hashes here.

Provenance

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