Skip to main content

Drive the Contextractor Node crawler/extractor from Python — clean main-content text in txt, markdown, json, or html.

Project description

contextractor

Contextractor

Crawl web pages and extract clean main-content text — txt, markdown, json, or html — from Python. Built on rs-trafilatura (extraction) and Crawlee + Playwright (crawling).

This package is a thin, typed wrapper that drives the bundled Node engine — it does not reimplement the crawler. A self-contained Node runtime ships with the wheel (via nodejs-wheel-binaries), so no Node.js install is required.

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

import contextractor

summary = contextractor.extract(
    ["https://example.com"],
    save=["markdown-kvs"],
    output_dir="./out",
    max_requests_per_crawl=10,
)
print(summary)
# ExtractSummary(total=1, succeeded=1, failed=0, skipped=0,
#                output_dir='/abs/out', manifest_path='/abs/out/manifest.json')

Extracted files and a manifest.json index are written to output_dir (default: ./contextractor-output). The manifest is a JSON array of records, each tagged status: "success" | "failed" | "skipped".

Async

import asyncio
import contextractor

async def main():
    summary = await contextractor.aextract(
        ["https://example.com", "https://example.org"],
        save=["markdown-dataset", "original-kvs"],
        output_dir="./out",
        max_concurrency=5,
    )
    print(summary.succeeded, "of", summary.total)

asyncio.run(main())

Single-page extraction

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

import contextractor

markdown = contextractor.extract_one("https://example.com")
print(markdown)  # str — markdown is the default format

Request several formats to get a dict keyed by format:

contents = contextractor.extract_one(
    "https://example.com",
    formats=["markdown", "json", "original"],
)
print(contents["markdown"])  # extracted markdown
print(contents["original"])  # raw page HTML

Formats: txt, markdown (default), json, html, original (the raw page HTML). With one requested format the return value is a str; with several it is a dict[str, str]. extract_one accepts the single-page subset of the crawl options (ExtractOneOptions) — e.g. proxy, mode, user_agent, cookies, headers, headless — but not crawl-frontier options like globs or max_crawl_depth. A page that cannot be fetched or extracted raises ContextractorError. If the page yields no content for one of several requested formats, that format's key is simply absent from the returned dict; when the single requested format yields no content, ContextractorError is raised.

Async single page

import asyncio
import contextractor

async def main():
    markdown = await contextractor.aextract_one("https://example.com")
    print(markdown)

asyncio.run(main())

Return value

extract() / aextract() return an ExtractSummary:

Field Meaning
total Number of records in the manifest
succeeded / failed / skipped Counts by record status
output_dir Absolute path where files + manifest were written
manifest_path Absolute path to manifest.json

Partial failures (some URLs failed) do not raise — they are reflected in summary.failed. Validation/config errors and real crawl failures raise ContextractorError; a missing browser raises MissingBrowserError pointing you at python -m contextractor install.

Options

All crawl options are typed keyword arguments (ExtractOptions). A selection:

Option Type Notes
save list[str] format-destination tokens: {txt,markdown,json,html,original}-{dataset,kvs} (e.g. markdown-kvs, original-dataset). Default markdown-kvs; list a format twice to save to both. Saving original/html to the dataset risks OOM on large pages
mode str precision, balanced (default), recall
max_requests_per_crawl int 0 = unlimited
max_crawl_depth int 0 = unlimited
globs / exclude list[str] enqueue / skip URL patterns
headless bool False runs a headed browser
block_media / images bool toggle media loading / image extraction
links / comments / tables bool False excludes that content
proxy list[str] http, https, socks4, socks5 URLs
cookies list[dict] initial cookies (JSON)
headers dict[str, str] custom HTTP headers (JSON)
selector str restrict extraction to a CSS selector
deduplication str minimal, standard (default), aggressive
output_dir str where files + manifest are written

Boolean options that have a CLI default emit a flag only when you set them. Editor autocomplete and type-checkers see every option via the ExtractOptions TypedDict.

Config file

Share configuration across runs with a JSON config file:

{
  "mode": "precision",
  "save": ["markdown-kvs", "json-dataset"],
  "maxRequestsPerCrawl": 25,
  "maxCrawlDepth": 2
}
contextractor.extract(
    ["https://example.com"],
    config_file="config.json",
    output_dir="./out",
)

Keyword arguments override values from the config file.

Proxies

Only http, https, socks4, and socks5 proxy URLs are accepted; an unsupported scheme raises ProxySchemeError before anything runs. Proxy credentials are never echoed in errors or logs.

contextractor.extract(
    ["https://example.com"],
    proxy=["http://user:pass@proxy.example.com:3128"],
    output_dir="./out",
)

Browser provisioning

Browsers are not bundled in the wheel. Run python -m contextractor install once to download Chromium for the bundled engine. The standard PLAYWRIGHT_BROWSERS_PATH environment variable is honored.

Advanced

  • CONTEXTRACTOR_NODE_PATH — point at a host Node binary to use instead of the bundled runtime.
  • storage_dir — reuse a Crawlee storage directory across runs (defaults to a private temporary directory cleaned up after each call).
  • timeout — per-process wall-clock limit (seconds).

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.1.tar.gz (21.6 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.1-py3-none-win_amd64.whl (29.3 MB view details)

Uploaded Python 3Windows x86-64

contextractor-0.4.1-py3-none-manylinux_2_28_x86_64.whl (29.3 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

contextractor-0.4.1-py3-none-manylinux_2_28_aarch64.whl (29.2 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

contextractor-0.4.1-py3-none-macosx_13_0_x86_64.whl (29.3 MB view details)

Uploaded Python 3macOS 13.0+ x86-64

contextractor-0.4.1-py3-none-macosx_13_0_arm64.whl (29.2 MB view details)

Uploaded Python 3macOS 13.0+ ARM64

File details

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

File metadata

  • Download URL: contextractor-0.4.1.tar.gz
  • Upload date:
  • Size: 21.6 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.1.tar.gz
Algorithm Hash digest
SHA256 cbdb9eb63c61a96523b764dc3bc6640e6bf708e00aafe8041f6ba707b9ebdb2b
MD5 2c65ea5ca008e718f7f0c8be2d5210ed
BLAKE2b-256 f182bf735aa9362063b878d67a8ebfea2907cb838b7be5a7ccb06de3d85f3fdf

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: contextractor-0.4.1-py3-none-win_amd64.whl
  • Upload date:
  • Size: 29.3 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for contextractor-0.4.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 6024b2159718798f49ef0f12634509152e1bd0cf0a720f8dea0c859a7483ffa2
MD5 5fed8570c932aacf4de48e4be26a7a17
BLAKE2b-256 113d49b7cd1416121fbef31a3aa5132c67396609b6d126ebab47febff895b350

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for contextractor-0.4.1-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 090755b5fe0ff6ab0d6033844ee4a266b4e954d1a4e1bd17815f9cdef3a56d12
MD5 e0e320559124cee88a9da9d58455adf4
BLAKE2b-256 d07d8ef3945042a5dc51bcc229c13b36e4a0bc704e26b3fb1529466c3f4d2618

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for contextractor-0.4.1-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 eb6eff1f53e5a9103f34e8706104880ab260d61ff9f85de4dee0868b00f41637
MD5 08cb7b0812f2674796817483798a62c7
BLAKE2b-256 2193a2b33ea9a5d3e3e1bdca6bc235751830c0c5875cd0ab5229adf0854fa3b3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for contextractor-0.4.1-py3-none-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 88937f061d5e6bfa4f666c4eb882340dfea7616c380e5779bd24bdf60fa58a54
MD5 74ad2d46cbc15219db4e64cfb2821473
BLAKE2b-256 d91173d2710f7e0d23c55840230e36b4d96910e030b60b909c11507a67642e93

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for contextractor-0.4.1-py3-none-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 28ba3456e4daf243d546404ef2e06f16502e6fc2124a7305a266bb5504d139a6
MD5 3a3cd43d9773762f2f9efa10b55a21b2
BLAKE2b-256 62d306e52ce9dd4f7b4fa1d346d0c1e314d31be48cc0c41967d31d05297b4cc3

See more details on using hashes here.

Provenance

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