Skip to main content

Drive the Contextractor Node crawler/extractor from Python; clean main-content text in 5 formats.

Project description

contextractor

Contextractor

Details & badges:

Also available as:

Social:

Drive the Contextractor Node crawler/extractor from Python; clean main-content text in 5 formats.

⚠️ 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 API Python library
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

The npm CLI is the reference surface for this wrapper.

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.10.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.10-py3-none-win_amd64.whl (29.0 MB view details)

Uploaded Python 3Windows x86-64

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

Uploaded Python 3manylinux: glibc 2.28+ x86-64

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

Uploaded Python 3manylinux: glibc 2.28+ ARM64

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

Uploaded Python 3macOS 13.0+ x86-64

contextractor-0.4.10-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.10.tar.gz.

File metadata

  • Download URL: contextractor-0.4.10.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.10.tar.gz
Algorithm Hash digest
SHA256 3adf4292d0a270f0a2ef349693b43f78108d70bab8e25a83e21bdbb081068f68
MD5 7faa5bc8fa0cde49f47d80bc06034f7b
BLAKE2b-256 feec6577adc3f342852ff8aeed837a66eb531e134f6dd3dd53c6db3735af85b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for contextractor-0.4.10.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.10-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for contextractor-0.4.10-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 1aa19a6dd74169e6efac8408bf92b75f4c2e9bac28b2edfd2d0afe1462bd26a1
MD5 2761aa0b4b7459dc70cf65c4111ed24e
BLAKE2b-256 e981d5fd0bc0e00b24e6f9066816279b30cef723f76f4fdacde2b981ab0ca971

See more details on using hashes here.

Provenance

The following attestation bundles were made for contextractor-0.4.10-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.10-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for contextractor-0.4.10-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 866f9f176308097445471b94984f0171c9e36700d7ca615f6a4d42f5998247d6
MD5 71c967617c7abd53ea3815c18cb0fd43
BLAKE2b-256 d799172e12f04f42679a8baa865553e0be549d543bca1042dca8f65649c5d6b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for contextractor-0.4.10-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.10-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for contextractor-0.4.10-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 5c6fa91df5db9b16218630bfc5fe7875d3d374b0b6f72314255f90dc20117486
MD5 9578275d8b89d683052a2353280ae00c
BLAKE2b-256 8d6eff869f183038348164de320f7af3c5bee2a39cea6c8e8679efc3cc87e17c

See more details on using hashes here.

Provenance

The following attestation bundles were made for contextractor-0.4.10-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.10-py3-none-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for contextractor-0.4.10-py3-none-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 bada38500a302535741551009f91a42ea0080bdeda65cc849fbd5e4c2ca1d207
MD5 74bf246a9e7d7fe3486e31163d74e3e6
BLAKE2b-256 dec0132973e1d8e53cfa1ff58dddbd819d5254e8a23414b03ec7b2af64720963

See more details on using hashes here.

Provenance

The following attestation bundles were made for contextractor-0.4.10-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.10-py3-none-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for contextractor-0.4.10-py3-none-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 d2e46eeb6d66712d8212acbac3f1b9d69d2808322c7fd79a4b0c013687877487
MD5 f205b8a96a4f43b6ee2b02408dc43e6f
BLAKE2b-256 9a55f0c8a19e2c0b3de04cff9e46bd031a61e66641bcd707051bcf40eb0860a7

See more details on using hashes here.

Provenance

The following attestation bundles were made for contextractor-0.4.10-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