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 PyPI version PyPI downloads license

Also available as:

Online playground playground, help | Apify Actor actor, help | NPM package CLI & lib package, CLI help, lib 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.

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.

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.13.tar.gz (23.2 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.13-py3-none-win_amd64.whl (29.0 MB view details)

Uploaded Python 3Windows x86-64

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

Uploaded Python 3manylinux: glibc 2.28+ x86-64

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

Uploaded Python 3manylinux: glibc 2.28+ ARM64

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

Uploaded Python 3macOS 13.0+ x86-64

contextractor-0.4.13-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.13.tar.gz.

File metadata

  • Download URL: contextractor-0.4.13.tar.gz
  • Upload date:
  • Size: 23.2 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.13.tar.gz
Algorithm Hash digest
SHA256 32653bc61137f499d6eb82528e873377dfcebc49b222d291309195fb93b17a6c
MD5 e39a0eaa5c8dcdcae9ea0e53e211bdef
BLAKE2b-256 d30c14c04b115062d23a925fee13d1c81255225ed8f0d8ab622de93eb9c4715e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for contextractor-0.4.13-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 5ae47da7549ed22dd4fed36b90c3fd626dc86f4492839d86842c44aeb5378ea0
MD5 02ecc1c6cc4d8df4f092a3ce6062e466
BLAKE2b-256 9176588860a337a2a5ca5cefcf38afc0219ecee715495a6a6945d0cf14f53746

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for contextractor-0.4.13-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1ff9f45274b2a0d73c4262e68a18a7cb13aebd8254f9e71949ef5244dfdcfe4a
MD5 d56f82ede44dd4e06208f264fbf5ff80
BLAKE2b-256 fae5bbd4986dd34dc7236c0f9b59708c72cb725f63493050e8e36ab2436ec4c3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for contextractor-0.4.13-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b6659221d3f25f6f4f6aca381a29e0ae46644d855ef24ff582cedb4b30ce7426
MD5 fad4528f688df49387fa79bc81e6d33d
BLAKE2b-256 e0a866cf1e11bb37df386bbf5dbb469f9ada61b041801027820843200604b354

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for contextractor-0.4.13-py3-none-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 4fa074a347c070a5ffb91298ef0fbc0a2425b2478b9cedb34017d0358279652f
MD5 ea365495e0887f64ad5f3dfc76575459
BLAKE2b-256 37874208cc2377aa582a3397d9bccb9b1d9e5ed767ff05680b402804b12c1aa4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for contextractor-0.4.13-py3-none-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 948dc71c98d09784c8dd08f323eefd58649330cbfc7beea7e7c2309f23694b57
MD5 35a9303cf8bfb4654ff1085a974f190e
BLAKE2b-256 2104dd648257550e6b5b5c8a4f6df425c5345bc962d7da25456dee53046ef3b4

See more details on using hashes here.

Provenance

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