Skip to main content

contextfetch

Python client for the ContextFetch API: web search, pages as Markdown, extractive answers, research, crawl and site maps for AI agents.

  • No dependencies: standard library only (urllib, json).
  • Typed: ships py.typed; responses are TypedDicts.
  • Python 3.9 or newer.

Install

pip install contextfetch

Quickstart

from contextfetch import ContextFetch

client = ContextFetch()  # reads CONTEXTFETCH_API_KEY; with no key it uses the keyless tier

res = client.search("python asyncio timeout", num_results=5, highlights=True, pruned_context=True)
for r in res["results"]:
    print(r["url"], r.get("title"))
    print(r.get("prunedContext", "")[:300])

page = client.read("https://docs.python.org/3/library/asyncio-task.html", query="task groups")
print(page.markdown)

No key yet? Get a free starter key (one per network, no signup):

key = ContextFetch().free_key()["apiKey"]
client = ContextFetch(key)

Methods

Method Endpoint
search(query, *, num_results, include_domains, exclude_domains, start_published_date, text, highlights, pruned_context) POST /v1/search
find_similar(url, *, ...same options as search) POST /v1/findSimilar
contents(urls, *, text=True, highlights, pruned_context) POST /v1/contents
answer(query, *, num_results, text) POST /v1/answer (extractive: passages quoted verbatim with [n] citations)
research(query, *, sub_queries, num_results_per_query) POST /v1/research
crawl(url, *, limit, max_depth, max_breadth, query, include_paths, exclude_paths) POST /v1/crawl
map(url, *, limit, include_paths, exclude_paths) POST /v1/map
read(url, *, query) GET /r/{url}, returns a Page (markdown, raw_tokens, output_tokens, token_savings)
balance() GET /v1/balance
free_key() POST /v1/keys/free

text, highlights and pruned_context take True or an options object as described in the API reference, for example highlights={"query": "task groups", "highlightsPerUrl": 2}. Responses are the API's JSON as dicts, with the API's field names (publishedDate, prunedContext, ...).

Options: ContextFetch(api_key=None, *, base_url="https://api.contextfetch.dev", timeout=60.0).

Errors

Every error is a ContextFetchError with status, code (the body's error field) and body.

  • AuthenticationError: HTTP 401, the key is not recognised.
  • PaymentRequiredError: HTTP 402, credits or the keyless allowance ran out. payment_url is a one-click checkout link and prompt_to_user is a sentence to show your user; stop retrying until they pay.
  • APIConnectionError: no response (DNS, connection or timeout).
from contextfetch import ContextFetch, PaymentRequiredError

try:
    ContextFetch().search("rust async runtimes")
except PaymentRequiredError as e:
    print(e.prompt_to_user)  # includes e.payment_url

Development

python -m unittest discover tests                                       # unit tests, local fake server
CONTEXTFETCH_API_KEY=... python -m unittest tests.test_live -v          # live smoke test, a few credits

License

MIT

Metadata

Release files for contextfetch 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for contextfetch 0.1.0
File Size Uploaded Provenance
contextfetch-0.1.0.tar.gz 9.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for contextfetch 0.1.0
File Interpreter ABI Platform
contextfetch-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.6 kB

Release files / contextfetch-0.1.0.tar.gz

Download URL contextfetch-0.1.0.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9bd68db260f8dd0e040c6ecb25202a43f47c9a1f4c7ee458ee0e38dacc6e1222
BLAKE2b-256 checksum
How to use checksums
0a04a5734eb14bcd709a981898547efb9c21f4a98a907cc699d8c982faca174f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / contextfetch-0.1.0-py3-none-any.whl

Download URL contextfetch-0.1.0-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a1cc26525b274bba76ba375374b8a359e49c1dba3eb4810f47684fda0fe8ca18
BLAKE2b-256 checksum
How to use checksums
f2d136a075203eefd5db29b88b42999efa729b81fc2ce90cc0ee0010555b29f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Security for contextfetch 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page