Metadata-Version: 2.5
Name: contextfetch-haystack
Version: 0.1.0
Summary: Haystack integration for the ContextFetch web search and Markdown API
Project-URL: Documentation, https://github.com/lachy3433/contextfetch-haystack#readme
Project-URL: Issues, https://github.com/lachy3433/contextfetch-haystack/issues
Project-URL: Source, https://github.com/lachy3433/contextfetch-haystack
Author: ContextFetch
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: ContextFetch,Fetcher,Haystack,Markdown,Web Search
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: Implementation :: CPython
Requires-Python: >=3.11
Requires-Dist: contextfetch>=0.1.0
Requires-Dist: haystack-ai>=2.24.1
Description-Content-Type: text/markdown

# contextfetch-haystack

[![PyPI - Version](https://img.shields.io/pypi/v/contextfetch-haystack.svg)](https://pypi.org/project/contextfetch-haystack)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/contextfetch-haystack.svg)](https://pypi.org/project/contextfetch-haystack)

[Haystack](https://haystack.deepset.ai/) components for the [ContextFetch API](https://contextfetch.dev/docs/reference):

- `ContextFetchWebSearch`: searches the web and returns the results as Documents, with page content as Markdown.
- `ContextFetchFetcher`: fetches URLs and returns each page as a Markdown Document.

## Installation

```bash
pip install contextfetch-haystack
```

## Usage

```python
from haystack_integrations.components.fetchers.contextfetch import ContextFetchFetcher
from haystack_integrations.components.websearch.contextfetch import ContextFetchWebSearch

websearch = ContextFetchWebSearch(top_k=3)
result = websearch.run(query="What are asyncio task groups?")
for doc in result["documents"]:
    print(doc.meta["title"], doc.meta["url"])

fetcher = ContextFetchFetcher()
pages = fetcher.run(urls=["https://docs.python.org/3/library/asyncio-task.html"])
print(pages["documents"][0].content[:500])
```

Both components read the API key from the `CONTEXTFETCH_API_KEY` environment variable. Without a key, requests use
the keyless tier, which has a small daily allowance per IP. Get a key at
[contextfetch.dev/get-started](https://contextfetch.dev/get-started).

`ContextFetchWebSearch` sends `pruned_context=True` by default, so each Document holds the page pruned to the parts
relevant to the query. Pass `search_params={"text": True}` for whole pages, or `{"highlights": True}` for the
most relevant chunks. Other keys: `include_domains`, `exclude_domains`, `start_published_date`.

## Development

```bash
hatch run test:unit         # unit tests, no network
hatch run test:integration  # live API tests; they run only when CONTEXTFETCH_API_KEY is set
hatch run test:types
hatch run fmt-check
```

## License

`contextfetch-haystack` is distributed under the terms of the [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html)
license.
