This release is a pre-release and may not be stable for production use.
Apify-Haystack integration
The Apify-Haystack integration allows easy interaction between the Apify platform and Haystack.
Apify is a platform for web scraping, data extraction, and web automation tasks. It provides serverless applications called Actors for tasks like crawling websites and scraping Facebook, Instagram, and Google results.
Haystack offers an ecosystem of tools for building, managing, and deploying search engines and LLM applications.
Installation
Apify-haystack is available as the apify-haystack package on PyPI. It requires Python 3.11 or newer and Haystack 3.
pip install apify-haystack
Components
ApifyDatasetFromActorCallruns an Actor, waits for it to finish, and loads its default dataset.ApifyDatasetFromTaskCalldoes the same for a saved Actor task.ApifyDatasetLoaderloads an existing dataset by its ID.ApifyWebSearchsearches the web with the RAG Web Browser Actor and returns the content of the top result pages.ApifyActorToolis a tool for Haystack Agents that runs any Actor and returns its dataset items. It takes its parameters from the Actor's input schema, and it marks the items it hands to the LLM as untrusted external content to guard against prompt injection.
The dataset components turn dataset items into Haystack Document objects with a mapping function. Without one, they use default_dataset_mapping_function, which takes the markdown or text of website and search Actors with the page url, title, and description as meta, and the whole item as JSON for other Actors. Every component also has run_async, which Pipeline.run_async uses to run it without blocking the event loop. When an Actor or task run finishes with any status other than SUCCEEDED, the component raises a RuntimeError instead of loading a partial dataset.
The components read your Apify API token from the APIFY_TOKEN environment variable, or from APIFY_API_TOKEN if APIFY_TOKEN isn't set. To pass the token differently, use a Haystack Secret, for example apify_token=Secret.from_env_var('MY_APIFY_TOKEN').
Examples
Crawl a website using Apify's Website Content Crawler and convert it to Haystack Documents
You need an Apify account and API token to run this example. You can start with a free account at Apify and get your API token.
In the example below, set the APIFY_TOKEN environment variable and run the script:
from haystack import Document
from apify_haystack import ApifyDatasetFromActorCall
actor_id = 'apify/website-content-crawler'
run_input = {
'maxCrawlPages': 3, # limit the number of pages to crawl
'startUrls': [{'url': 'https://haystack.deepset.ai/'}],
}
def dataset_mapping_function(dataset_item: dict) -> Document:
return Document(content=dataset_item.get('text'), meta={'url': dataset_item.get('url')})
actor = ApifyDatasetFromActorCall(
actor_id=actor_id, run_input=run_input, dataset_mapping_function=dataset_mapping_function
)
print(f'Calling the Apify Actor {actor_id}. Crawling will take some time.')
print('You can monitor the progress at: https://console.apify.com/actors/runs')
dataset = actor.run()['documents']
print(f'Loaded {len(dataset)} documents from the Apify Actor {actor_id}:')
for d in dataset:
print(d)
Search the web
ApifyWebSearch returns the top result pages as Markdown Document objects, with the page url, title, and description in meta, and their URLs in links:
from apify_haystack import ApifyWebSearch
search = ApifyWebSearch(top_k=3)
result = search.run(query='What is Haystack?')
for document in result['documents']:
print(document.meta['url'], document.meta['title'])
Give an Agent access to an Actor
ApifyActorTool lets a Haystack Agent run an Actor. Limit dataset_items_limit to keep the tool output within the model's context window. For pay-per-event Actors, max_total_charge_usd caps what each run the Agent starts can cost:
from haystack.components.agents import Agent
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from apify_haystack import ApifyActorTool
tool = ApifyActorTool('apify/rag-web-browser', dataset_items_limit=3, max_total_charge_usd=0.5)
agent = Agent(chat_generator=OpenAIChatGenerator(), tools=[tool])
result = agent.run([ChatMessage.from_user('What is new in Haystack 3?')])
print(result['last_message'].text)
Save and load a pipeline
The components and the tool support Haystack serialization. The token is saved as the name of its environment variable, never as its value. Haystack 3 only loads classes and functions from trusted modules, so allow apify_haystack and the module with your mapping function:
from haystack import Pipeline
yaml = pipeline.dumps()
restored = Pipeline.loads(yaml, allowed_modules=['apify_haystack', 'my_project.mapping'])
More examples
The examples directory has more examples:
- Load a dataset from Apify and convert it to a Haystack Document
- Call Website Content Crawler and convert the data into the Haystack Documents
- Crawl websites, retrieve text content, and store it in the
InMemoryDocumentStore - Retrieval-Augmented Generation (RAG): Extracting text from a website & question answering
- Analyze your Instagram comments' vibe with Apify and Haystack
Support
If you find any bug or issue, please submit an issue on GitHub. For questions, you can ask on Stack Overflow, in GitHub Discussions or you can join our Discord server.
Contributing
Code contributions are welcome. If you have ideas for improvements, submit an issue or create a pull request. For contribution guidelines, see CONTRIBUTING.md.
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Metadata
Release files for apify-haystack 0.1.8b3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| apify_haystack-0.1.8b3.tar.gz | 23.5 kB | With provenance | Details for apify_haystack-0.1.8b3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| apify_haystack-0.1.8b3-py3-none-any.whl | Python 3 | none | any | Details for apify_haystack-0.1.8b3-py3-none-any.whl |
Total release size: 43.2 kB
Release files / apify_haystack-0.1.8b3.tar.gz
| Download URL | apify_haystack-0.1.8b3.tar.gz |
|---|---|
| Size | 23.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d602496a275f1706911100e46ead1f96bc3f2498e66fe27a056040c831f6fa46
|
|
BLAKE2b-256 checksum How to use checksums |
ca88cad19fcf2faa3c5cbf065e07b63e6151f375739f5f7abc06e84892c29af5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logRelease files / apify_haystack-0.1.8b3-py3-none-any.whl
| Download URL | apify_haystack-0.1.8b3-py3-none-any.whl |
|---|---|
| Size | 19.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e5c783bd84399a20a34d843e169dc509efbcd45d4e51db11c467cda89288ab06
|
|
BLAKE2b-256 checksum How to use checksums |
f4ebcfcd4adea7691f8e548a13768400d6610bde7863dc36f71a7bda5c6404da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logSecurity for apify-haystack 0.1.8b3
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for apify_haystack-0.1.8b3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logA 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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.