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

Uploaded Python 3Windows x86-64

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

Uploaded Python 3manylinux: glibc 2.28+ x86-64

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

Uploaded Python 3manylinux: glibc 2.28+ ARM64

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

Uploaded Python 3macOS 13.0+ x86-64

contextractor-0.4.2-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.2.tar.gz.

File metadata

  • Download URL: contextractor-0.4.2.tar.gz
  • Upload date:
  • Size: 22.1 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.2.tar.gz
Algorithm Hash digest
SHA256 a8cff2f8e8848217b379363afe40a1f6f93d1cf10f3342ae47a2daf05fe31de1
MD5 d86e5d6ac0b461f389f3c1031ebe3d20
BLAKE2b-256 c6b24869be1582ceee7cdd720954b7184c4875333d26b99c635faeb848f41c13

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: contextractor-0.4.2-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.2-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 853d7517137f8a2871e6392798ebbe1d0e3bd0abe7fc49d69ac4d18a77d74c22
MD5 5b203c1b63a4d3bb025d0058c434d73f
BLAKE2b-256 45900de1d69e05acf74b4fb44db803ae81d45f7d276888f92648a69a0633e4b5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for contextractor-0.4.2-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e834f390e23f722580876d347bd50fc0c08b886d40ce2aaa6bf92498a55053e1
MD5 e43c5426470d557e234081b43577612a
BLAKE2b-256 3883ecd161ea156a3d27af4cbb49e9628e01610949de67672ce6992214ceaac2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for contextractor-0.4.2-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7c8a2c4ff31963df05295179576b646efc17bc188b94434a40ead7f2f1f06f94
MD5 0cfec0b6e83b95272c31dcb60c42ec95
BLAKE2b-256 e7b05572550b37f6c35c3f2557d96b1fab8988fc01bfc5cb3094a58b205917fe

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for contextractor-0.4.2-py3-none-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 972ffe23710196ff0102f5bbdcb5dc02d8d605f60051a239239cb4b7d7e2042f
MD5 0e1626f22cab0a200a5df54772fb06e8
BLAKE2b-256 1977af058b0bfaf1bfa61a1a3ca58d0774ab8a331bd38513e31e40cca806b105

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for contextractor-0.4.2-py3-none-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 bde3e6dcec8a9b9a5e6c392500bf4dbf22f0646083b47ef006fe2b445f6a8113
MD5 7df160cf4473e12cd294ac9e0ee1cbc3
BLAKE2b-256 fff3efcc977e736d0cfaa1589eba0f36d882a28c4be0f77fad03ceb4cd5e4ac6

See more details on using hashes here.

Provenance

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