Skip to main content

Drive the Contextractor Node crawler/extractor from Python; clean main content in txt/markdown/json/html, plus raw original HTML.

Project description

contextractor

Contextractor

Details & badges: PyPI version PyPI downloads license

Also available as: Online playground [playground, help] | Apify Actor [actor, help] | NPM package [package, help] | Source code on GitHub

Social: X (Twitter)

Drive the Contextractor Node crawler/extractor from Python; clean main content in txt/markdown/json/html, plus raw original HTML.

⚠️ Alpha / experimental. This Python wrapper for Contextractor is currently an alpha, experimental release — not fully tested or officially supported, though still maintained.

Crawl web pages and extract clean main-content text — txt, markdown, json, html, or raw original HTML — from Python. Built on rs-trafilatura (extraction) and Crawlee with Playwright or a pure-HTTP Cheerio crawler (crawling).

This package is a thin, typed wrapper that drives the bundled Node engine. A self-contained Node runtime is installed automatically as a dependency (nodejs-wheel-binaries), so no separate Node.js install is required.

Homepage & docs: www.contextractor.com · Python guide

Contents

Why Contextractor

Contextractor ships the Rust port of Trafilatura as a native (napi-rs) binding — no Python extraction runtime. On the Scrapinghub article set it scores an F1 of 0.966 (precision 0.942, recall 0.991) — ahead of go-trafilatura (0.960) and the original Python Trafilatura (0.958); see the benchmark write-up for the methodology.

It is free and open source (Apache-2.0), runs locally with no API key and no per-page credits, and its Markdown output is typically 80–90% fewer tokens than the raw HTML — cheap to feed to an LLM.

Contextractor Firecrawl Jina Reader Crawl4AI
Extraction engine rs-trafilatura (heuristic + ML routing) LLM / heuristic ReaderLM neural model LLM / heuristic
Runtime Rust + Node (no Python engine) hosted API / self-host hosted API Python
Surfaces Apify Actor · npm CLI · npm library · PyPI API · SDKs · self-hosted · MCP API Python library · crwl CLI · Docker REST API · MCP
Output formats txt · markdown · json · html · original markdown · html · etc. markdown · html · text · screenshot · etc. markdown · etc.
Crawling Crawlee + Playwright (adaptive / browser / HTTP) built-in none (single URL) built-in

Install

pip install contextractor
python -m contextractor install   # one-time: download the Chromium browser

Platform wheels are published for macOS (arm64, x86_64), Linux (x86_64, aarch64; glibc ≥ 2.28), and Windows (x64). Requires Python 3.12+.

Quick start

Crawl one or more URLs and write extracted files plus a manifest.json index to output_dir:

import contextractor

summary = contextractor.extract(
    ["https://en.wikipedia.org/wiki/Web_scraping"],
    save=["markdown-kvs"],
    output_dir="./out",
)
print(summary.succeeded, "of", summary.total)

Each save token is <format>-<kvs|dataset> — the format name plus the destination — so it reads markdown-kvs, not bare markdown (the bare names like markdown and json are what extract_one(formats=[...]) takes instead).

An async variant, aextract(), takes the same arguments. Partial failures do not raise — they are reflected in summary.failed; validation and real crawl failures raise ContextractorError, and a missing browser raises MissingBrowserError pointing you at python -m contextractor install.

Single-page extraction

extract_one() crawls exactly one URL (no link-following) and returns the extracted content directly — nothing is written to disk:

import contextractor

markdown = contextractor.extract_one("https://en.wikipedia.org/wiki/Web_scraping")  # -> str

contents = contextractor.extract_one(                                # -> dict[str, str]
    "https://en.wikipedia.org/wiki/Web_scraping",
    formats=["markdown", "json", "original"],
)

With one requested format the return value is a str; with several it is a dict[str, str]. aextract_one() is the async variant.

Options

Every crawl option is a typed keyword argument; the ExtractOptions / ExtractOneOptions TypedDicts are the authoritative list of keywords and accepted values, surfaced to editors and type checkers (e.g. save, mode, proxy, cookies, headers, max_crawl_depth, globs). See also the Python documentation. Each Python keyword maps one-to-one onto a flag of the npm CLI, documented at contextractor.com/help/npm.

Only http, https, socks4, and socks5 proxy URLs are accepted; credentials are never echoed in errors or logs. Set CONTEXTRACTOR_NODE_PATH to use a host Node binary instead of the bundled runtime.

Links

Contributing

Issues and pull requests are welcome at the issue tracker. The extraction engine, npm CLI, and Apify Actor all live in the same source repository.

License

Apache-2.0

Project details


Download files

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

Source Distribution

contextractor-0.4.12.tar.gz (23.3 kB view details)

Uploaded Source

Built Distributions

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

contextractor-0.4.12-py3-none-win_amd64.whl (29.0 MB view details)

Uploaded Python 3Windows x86-64

contextractor-0.4.12-py3-none-manylinux_2_28_x86_64.whl (29.1 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

contextractor-0.4.12-py3-none-manylinux_2_28_aarch64.whl (29.0 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

contextractor-0.4.12-py3-none-macosx_13_0_x86_64.whl (29.0 MB view details)

Uploaded Python 3macOS 13.0+ x86-64

contextractor-0.4.12-py3-none-macosx_13_0_arm64.whl (28.9 MB view details)

Uploaded Python 3macOS 13.0+ ARM64

File details

Details for the file contextractor-0.4.12.tar.gz.

File metadata

  • Download URL: contextractor-0.4.12.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for contextractor-0.4.12.tar.gz
Algorithm Hash digest
SHA256 a11065170d47e05b7e549a3771e0f05aeaa7fddd8724ea3e6580bc8cba0cbe0e
MD5 8356cd295c69ea8014fec283c5aae3db
BLAKE2b-256 f9202d1a57a61060175178b56676a05eacb1d3592930c773b50169402754aeee

See more details on using hashes here.

Provenance

The following attestation bundles were made for contextractor-0.4.12.tar.gz:

Publisher: release-pypi.yml on contextractor/contextractor

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

File details

Details for the file contextractor-0.4.12-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for contextractor-0.4.12-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 5130464315437642c35c729736d88bccb2dc15b554ae08c16b63c2ca7d833f2e
MD5 fcd73408b77d95eceb586be9a1c397bc
BLAKE2b-256 b5e35b62a5c8cd8d68925140a5f0d08001bded170f61bd166ab1f9677cfdaaaf

See more details on using hashes here.

Provenance

The following attestation bundles were made for contextractor-0.4.12-py3-none-win_amd64.whl:

Publisher: release-pypi.yml on contextractor/contextractor

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

File details

Details for the file contextractor-0.4.12-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for contextractor-0.4.12-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0dcd2cefa0bad70d86db1c54e904963bf3866c7675b35e01ee87d84b71bfb731
MD5 915e135dd2abf7f8f6e6fb1b635898df
BLAKE2b-256 dd553a94635ef967cffbe8745745ef59dcbbb9740daf6f600ac132cebc79c26b

See more details on using hashes here.

Provenance

The following attestation bundles were made for contextractor-0.4.12-py3-none-manylinux_2_28_x86_64.whl:

Publisher: release-pypi.yml on contextractor/contextractor

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

File details

Details for the file contextractor-0.4.12-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for contextractor-0.4.12-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e603282edc3c3a724eb871b0eab269ad7286f11ae673893a5b2628dc18f73d3a
MD5 dc25bbc2cc5f6187263918368786ed25
BLAKE2b-256 1736a86e8d6c679a20afb5c036e833eaf8c75b83eb446ce0d6a1b545f1ae584b

See more details on using hashes here.

Provenance

The following attestation bundles were made for contextractor-0.4.12-py3-none-manylinux_2_28_aarch64.whl:

Publisher: release-pypi.yml on contextractor/contextractor

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

File details

Details for the file contextractor-0.4.12-py3-none-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for contextractor-0.4.12-py3-none-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 ef1d0c5c2bb3cdf4a2e9be8b940be64805a46a9db852e3370ddfd64a7b57428b
MD5 41fbdc490a1ffcac958c60acc4581d49
BLAKE2b-256 46b24fca82d39cacfe24d96f1d8b7221b5ba3b78a38ab65fcbadbbc19cc357aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for contextractor-0.4.12-py3-none-macosx_13_0_x86_64.whl:

Publisher: release-pypi.yml on contextractor/contextractor

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

File details

Details for the file contextractor-0.4.12-py3-none-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for contextractor-0.4.12-py3-none-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 d7f2efd1e173d5ca0c34ea05bfd525ab9453391cae64097fa6c37f62ba82f874
MD5 2dc4c231dae93bc58a68e1409cac4e54
BLAKE2b-256 ffe878e9451f4ad86c982a64d52769283c3c64680d6ad7aa74a10bfac28738bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for contextractor-0.4.12-py3-none-macosx_13_0_arm64.whl:

Publisher: release-pypi.yml on contextractor/contextractor

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