Skip to main content

fasthtmlparser

CI PyPI

Website: fasthtmlparser.com: try the parser on any page, documentation and every language.

A fast HTML / XML parser for scraping, with XPath 1.0 and CSS selectors: Python bindings of the Rust port of z3l.FastHtmlParser. It is built for extracting data, not for building a DOM: a page becomes a flat list of tags that hold only positions in the source; text, attributes and entities are read when you ask for them. Parsing is 5–7x faster than selectolax and 20x faster than lxml (see below).

pip install fasthtmlparser

Python 3.10 or later. Wheels for Linux (glibc and musl), Windows and macOS, x86-64 and ARM64; no dependencies.

import fasthtmlparser as fh

doc = fh.parse(html, url="https://books.toscrape.com/")  # str or bytes; url resolves relative links

# CSS selectors, as querySelectorAll / querySelector
for pod in doc.css("article.product_pod"):
    title = pod.css_first("h3 a").attr("title")
    price = pod.css_first("p.price_color").text
    link = pod.css_first("h3 a").href          # absolute URL
ul.css("> li")                                 # the children of ul

# XPath 1.0
doc.xpath("//div[@class='card']//span[@class='price']")   # tags
doc.xpath_values("//a[contains(@href, '/product/')]/@href")
doc.xpath_value("//dt[.='Price']/following-sibling::dd[1]")
doc.xpath_value("count(//table//tr)")          # "12"

# compile once, reuse on any number of pages and threads
TITLES = fh.XPathQuery("//article//h3/a/@title")
TITLES.values(doc)
PRICES = fh.CssQuery("p.price_color")
PRICES.all(doc)

# search by name (any name, case-insensitive) and criteria, as in BeautifulSoup
pod = doc.find("article", class_="product_pod")
pod.find("p", class_="price_color").text
doc.find_all("a", attr=("rel", "next"))
doc.find("dt", text="Price").find_next_sibling("dd").text
doc.find("my-widget", id_starts_with="w-")
# criteria: class_, id, attr=(name, value), text, id_starts_with, text_starts_with, body, body_starts_with, source

# reading a tag
tag.name, tag.depth, tag.index, tag.pos   # pos: byte offsets in the UTF-8 source
tag.text              # visible text, entities decoded, whitespace collapsed
tag.text_line_breaks  # <br> and block elements → new lines, <p> and headings → paragraphs
tag.attr("data-src")  # decoded value, "" when missing; attr_raw(): as written
tag.attrs             # {"href": "...", "class": "..."}
tag.href, tag.src     # absolute URLs; href_from(base) / src_from(base)
tag.mailto, tag.tel   # the address of a mailto: link, the number of a tel: link
tag.body, tag.outer_html, tag.source   # inner HTML, the whole element, the opening tag

# navigation
tag.parent, tag.children, tag.next_sibling, tag.previous_sibling, tag.next, tag.previous
tag.find_parent("table"), tag.find_next("h2"), tag.text_after_until("br")

# the whole document
len(doc), doc[0], doc[-1], list(doc)    # every tag, comments included

A missing tag is None, a missing value is "". An invalid selector raises fh.CssSelectorError, an invalid XPath expression fh.XPathError (both are ValueErrors); xpath() on an expression that gives a number or string raises XPathError too (use xpath_value). The string methods compile and cache queries. A Node keeps its document alive, nodes compare equal when they are the same tag, and are hashable. The GIL is released while a page is parsed, and documents and compiled queries can be shared between threads. Type stubs are included.

CSS: type, *, #id, .class, attribute selectors with all operators and the i / s flags, the four combinators, selector lists, :first-child, :last-child, :only-child, :*-of-type, :nth-child(An+B [of S]) and its relatives, :not(), :is(), :where(), :has(), :empty, :root, :scope, :link, :checked, :disabled, :enabled, :required, :optional, :contains("text"). XPath: all axes except namespace, predicates, |, the operators and all XPath 1.0 functions, plus ends-with(), lower-case(), upper-case(). HTML rules apply: names are case-insensitive, the string-value of an element is its visible text, attribute values and text are decoded. HTML5 optional end tags (<li>, <p>, <td>, <option> without end tags) give the same elements as in a browser; there is no full HTML5 tree construction (no implied <tbody> or <html>), and documents are read-only.

Same results as the .NET version

tests/test_conformance.py runs the conformance data of the Rust crate through the Python package: on 117 pages (fixtures, broken markup, cut-off pages, CR LF, 600-deep nesting, ...) every tag's name, position, text, text with line breaks, attributes, navigation and links, and 569 XPath / CSS queries on the document and from three tags of each page, must give exactly what z3l.FastHtmlParser (.NET) gives. So the bindings are checked as well as the parser.

Benchmarks

python bench/bench.py (Python 3.14, AMD Ryzen 7 3800X, Windows; bench-results.md). Every library must extract the same records before anything is timed.

Parse a page:

Page fasthtmlparser selectolax (lexbor) lxml parsel BeautifulSoup (lxml)
quotes, 11 KB 19 μs 95 μs 495 μs 499 μs 4,368 μs
laptops, 38 KB 53 μs 306 μs 1,379 μs 1,420 μs 12,192 μs
books, 51 KB 65 μs 424 μs 1,547 μs 1,616 μs 15,273 μs
books x10, 510 KB 652 μs 3,531 μs 13,873 μs 14,886 μs 15,083 μs*
books without </li> </p> 59 μs 221 μs 1,460 μs 1,593 μs 14,393 μs

* BeautifulSoup with lxml stops at the first </html>: it finds 20 of the 200 books on that page.

Scrape a page: parse and extract the records (books: 20 × title, price, rating; quotes: 10 × text, author, tags).

Task fasthtmlparser selectolax lxml / parsel BeautifulSoup (lxml)
20 books, CSS 126 μs 587 μs parsel 2,543 μs 19,006 μs
20 books, XPath 217 μs lxml 2,715 μs
20 books, find 152 μs
10 quotes 74 μs 271 μs parsel 1,030 μs 5,984 μs

Build from source

Needs Rust 1.85+ and maturin:

python -m venv .venv && .venv/Scripts/activate   # or . .venv/bin/activate
pip install maturin pytest
maturin develop --release
pytest

Other languages

The same parser is available for:

Language Package Source
C# (.NET 9 and 10) z3l.FastHtmlParser on NuGet romanti3172/z3l.FastHtmlParser
Go github.com/romanti3172/fasthtmlparser romanti3172/fasthtmlparser
Rust fasthtmlparser on crates.io romanti3172/fasthtmlparser-rs
JavaScript / TypeScript z3l-fasthtmlparser on npm romanti3172/fasthtmlparser-js
Python fasthtmlparser on PyPI romanti3172/fasthtmlparser-py

License

Same terms as z3l.FastHtmlParser (see LICENSE.md): free for companies under USD 1M annual revenue and under 100 people, a commercial license above that. This is source-available, not an OSI open-source license.

Metadata

Release files for fasthtmlparser 0.1.2

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

Source distribution (sdist)

Source distribution for fasthtmlparser 0.1.2
File Size Uploaded Provenance Actions
fasthtmlparser-0.1.2.tar.gz 21.1 kB With provenance Details for fasthtmlparser-0.1.2.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for fasthtmlparser 0.1.2
File Actions
fasthtmlparser-0.1.2-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details for fasthtmlparser-0.1.2-cp310-abi3-win_arm64.whl
fasthtmlparser-0.1.2-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for fasthtmlparser-0.1.2-cp310-abi3-win_amd64.whl
fasthtmlparser-0.1.2-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details for fasthtmlparser-0.1.2-cp310-abi3-musllinux_1_2_x86_64.whl
fasthtmlparser-0.1.2-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details for fasthtmlparser-0.1.2-cp310-abi3-musllinux_1_2_aarch64.whl
fasthtmlparser-0.1.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for fasthtmlparser-0.1.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
fasthtmlparser-0.1.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details for fasthtmlparser-0.1.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
fasthtmlparser-0.1.2-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for fasthtmlparser-0.1.2-cp310-abi3-macosx_11_0_arm64.whl
fasthtmlparser-0.1.2-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for fasthtmlparser-0.1.2-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 4.2 MB

Release files / fasthtmlparser-0.1.2.tar.gz

Download URL fasthtmlparser-0.1.2.tar.gz
Size 21.1 kB
Tags Source
SHA-256 checksum
How to use checksums
33db0ddcdeba3e3eae71bbf8a675fc099be1dcf3f2a40eb093afa01bc5da5b84
BLAKE2b-256 checksum
How to use checksums
24859d4a5b85a6b67343bd1b88f994163fae3adc1ccae578c31425b2d857c3da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / fasthtmlparser-0.1.2-cp310-abi3-win_arm64.whl

Download URL fasthtmlparser-0.1.2-cp310-abi3-win_arm64.whl
Size 378.0 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
2cea7fc3b70997d2d55ef34e1de8085c2df6742730becdb5b09fbb7015a8e725
BLAKE2b-256 checksum
How to use checksums
6d1740dcb3d69f32fa30a261c0e700a73e2936c1a252c24586313c94e2d02e9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / fasthtmlparser-0.1.2-cp310-abi3-win_amd64.whl

Download URL fasthtmlparser-0.1.2-cp310-abi3-win_amd64.whl
Size 393.2 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
f17dbc0ecfb686f361e332c9bf76fb8df21c2b703aac7d94b61596a0aae058ca
BLAKE2b-256 checksum
How to use checksums
bcb907bad5a22716d0468b6d69c3954f9676d97f05b6d8f41d7d6659ba834391
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / fasthtmlparser-0.1.2-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL fasthtmlparser-0.1.2-cp310-abi3-musllinux_1_2_x86_64.whl
Size 733.6 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
b0794912862b21ca1a9a5e5ba0addb2ca3a6a217bb30433bf8fe73e8d6c62f72
BLAKE2b-256 checksum
How to use checksums
3151c711104a115f892661e4fbf1c6cd9557ac857a87992b6a5eb04a34156c3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / fasthtmlparser-0.1.2-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL fasthtmlparser-0.1.2-cp310-abi3-musllinux_1_2_aarch64.whl
Size 698.3 kB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
cc8ef1e2342747e3cca25c0887b013a61bdb557c80068c4bf57da61de540986d
BLAKE2b-256 checksum
How to use checksums
35ad9eab3ffa025dd2c86ace35ac8c9341a596d7dbbbd0f49350e6b3bfb25824
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / fasthtmlparser-0.1.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL fasthtmlparser-0.1.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 512.4 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
145dfaa0ebe9954299a9ad17bb10a7cac018913b3be83933e7dbe738c229d669
BLAKE2b-256 checksum
How to use checksums
5bece71ea2ebe5f0638f361a26326c9175311c52f9ea76a74b94ca7da710d115
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / fasthtmlparser-0.1.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL fasthtmlparser-0.1.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 521.2 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
090a6833a5340d050a14c9995eb1e35da614d16dd14b7fe34bec159537dd4e7b
BLAKE2b-256 checksum
How to use checksums
7b3e47198247dbbea4dc91e2df8ec8192b6f12c665a4a7711091ee01dc02b05e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / fasthtmlparser-0.1.2-cp310-abi3-macosx_11_0_arm64.whl

Download URL fasthtmlparser-0.1.2-cp310-abi3-macosx_11_0_arm64.whl
Size 464.5 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
92d97d132b1695faf4e6cb4ad6674f2e4ceef833e963020b6901beb327e82066
BLAKE2b-256 checksum
How to use checksums
b177daac1a6f917252cfa79cb7153dd23f71bdfc4580fdd3519ac926a96143b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / fasthtmlparser-0.1.2-cp310-abi3-macosx_10_12_x86_64.whl

Download URL fasthtmlparser-0.1.2-cp310-abi3-macosx_10_12_x86_64.whl
Size 478.5 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
c6fdd5d599d3e3c954e122cc9a4b3584e020bd2456bf93fc4560aa6505b7d480
BLAKE2b-256 checksum
How to use checksums
b93f80f3de86d25db5a66c24a958f98a120be200b3e7abd985a1b4b96c022da3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Security for fasthtmlparser 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 9 files in this release have been uploaded with provenance metadata.

Select from 9 files

Attestation for fasthtmlparser-0.1.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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