Skip to main content

htmlsift

Web main-content extraction: HTML in, clean text / HTML / markdown out. Trained on WebMainBench, scores each rendered line of a page as main content or boilerplate (nav, ads, cookie banners, and footers) and returns just the content.

Apache-2.0. Full documentation, diagrams, and benchmarks: https://github.com/koivualeksi/htmlsift

Results

model desc WMB test F1 seeds CPU (pages/s) GPU (pages/s) install
base 311M, 10 layers 0.9311 3 0.4 24.6 htmlsift[full]
unpublished 97M, 6 layers, int8 QAT 0.9256 3 0.9 30.2 —
mini int8 embedding table 0.9010 3 27.7 — htmlsift

GPU = RTX 4090, CPU = Ryzen 5 3600 single thread; WMB test = 544 pages (one of the 545 has no gold reference). On WMB (in-domain), mini scores ~15 F1 points above trafilatura at comparable CPU speed.

Cross-benchmark accuracy (zero-shot)

Trained on WMB, scored on benchmarks the model never saw. Each column uses that benchmark's own metric.

model WMB (ROUGE-5) WCXB (word-F1) DAnIEL (ROUGE-L)
base 0.9311 0.8633 0.9175
mini 0.9010 0.8474 0.8797
trafilatura 0.7525 0.8584 0.8265
readability 0.8016 0.7653 0.8925
resiliparse 0.7135 0.7909 0.7094

Model rows are 3-seed test means; heuristics are single deterministic runs. "Main content" is a labeling policy: htmlsift leads in-domain and stays competitive off-policy — retrain on your own labels if your definition differs. Details in the research repo.

Install

pip install htmlsift          # default: the mini model (CPU, ONNX)
pip install htmlsift[full]    # adds the base 311M model (torch; GPU-capable)
  • htmlsift — the mini model only; few dependencies (onnxruntime + tokenizers + lxml + numpy + huggingface-hub + w3lib). First use downloads ~230 MB of model files.
  • htmlsift[full] — adds torch + transformers to run base. First use of base downloads ~1 GB.

Requires Python 3.10+. Model files download from the Hugging Face Hub on first use and are cached; run htmlsift download <mode> to prefetch, or set HF_HUB_OFFLINE=1 to run from cache only.

Usage

from htmlsift import Extractor

ex = Extractor()                     # defaults to "mini"
ex.extract(html)                     # -> str (plain text)
ex.extract(html, output="html")      # structure, links, images kept
ex.extract(html, output="markdown")  # clean markdown: [text](url), ![alt](src)
ex.extract(html, with_blocks=True)   # -> (blocks, probs)

import htmlsift
htmlsift.extract(html)               # module-level convenience

Raw bytes are decoded for you (byte order mark, then encoding=, then <meta charset>, then utf-8 / cp1252):

ex.extract(response.content)                       # charset from the page itself
ex.extract(payload, encoding="windows-1251")       # charset from the HTTP / WARC header

Make links and image URLs absolute in html / markdown output (the page's <base href> is honoured):

ex.extract(html, output="markdown", base_url="https://example.com/blog/post")

The larger model, from htmlsift[full]:

ex = Extractor("base")               # 311M encoder; GPU when present, else CPU (with a warning)
ex = Extractor("base", device="cuda")  # require the GPU

mini is CPU-only; only base runs on the GPU.

Output modes

output what you get
text (default) selected content as plain text
html selected DOM, with structure / links / images kept
markdown clean markdown, links and images preserved

Command line

htmlsift extract page.html                          # main content of one page
curl -s https://example.com/a | htmlsift extract - --base-url https://example.com/a
htmlsift extract "crawl/*.html" --output markdown > out.jsonl   # one JSON line per file

Flags: --output, --mode, --device, --base-url, --encoding, --jsonl (records even for a single file). Failed files become {"path", "error"} records and the exit code is 1. Output is utf-8.

License

Apache-2.0. Model weights are distributed from the Hugging Face Hub, also under Apache-2.0, and are trained on WebMainBench (Apache-2.0); please attribute WebMainBench when you use them.

Metadata

Release files for htmlsift 0.2.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 htmlsift 0.2.0
File Size Uploaded Provenance Actions
htmlsift-0.2.0.tar.gz 57.7 kB With provenance Details for htmlsift-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for htmlsift 0.2.0
File Interpreter ABI Platform Actions
htmlsift-0.2.0-py3-none-any.whl Python 3 none any Details for htmlsift-0.2.0-py3-none-any.whl

Total release size: 92.1 kB

Release files / htmlsift-0.2.0.tar.gz

Download URL htmlsift-0.2.0.tar.gz
Size 57.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4ebf22c5f614d248ca951c7f35a2298f6bb8810d5e4a6a121d2bfe4565bc59ff
BLAKE2b-256 checksum
How to use checksums
5cafa1252f4925eba6d47ecde537afb66302c00965c6f50e0010176c569c13a0
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 2, 2026.

Transparency log

Release files / htmlsift-0.2.0-py3-none-any.whl

Download URL htmlsift-0.2.0-py3-none-any.whl
Size 34.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1fee18709a3cc68284d05d4135e4d092253194e1d7b3f85c29e12c9f603dd3f2
BLAKE2b-256 checksum
How to use checksums
3324fcb7a903bd0fc4c668c50903b7e1230aaf0ee99ae188b784bc811bf461f9
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 2, 2026.

Transparency log

Security for htmlsift 0.2.0

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for htmlsift-0.2.0.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 2, 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