{"id":32744667,"url":"https://github.com/apify/langchain-apify","last_synced_at":"2026-03-06T06:03:37.011Z","repository":{"id":275155592,"uuid":"925151266","full_name":"apify/langchain-apify","owner":"apify","description":"Apify integration for LangChain 🦜🔗","archived":false,"fork":false,"pushed_at":"2025-11-25T15:52:54.000Z","size":99,"stargazers_count":4,"open_issues_count":3,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2026-01-13T16:41:28.866Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apify.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-01-31T10:29:18.000Z","updated_at":"2025-11-25T15:52:54.000Z","dependencies_parsed_at":"2025-01-31T15:31:07.973Z","dependency_job_id":"8d36afd6-8574-4b84-8773-afb7dbe9ecb1","html_url":"https://github.com/apify/langchain-apify","commit_stats":null,"previous_names":["apify/langchain-apify"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/apify/langchain-apify","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apify%2Flangchain-apify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apify%2Flangchain-apify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apify%2Flangchain-apify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apify%2Flangchain-apify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apify","download_url":"https://codeload.github.com/apify/langchain-apify/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apify%2Flangchain-apify/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30164532,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T04:43:31.446Z","status":"ssl_error","status_checked_at":"2026-03-06T04:40:30.133Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-11-03T16:28:47.238Z","updated_at":"2026-03-06T06:03:36.985Z","avatar_url":"https://github.com/apify.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e 🎉 **Apify MCP server released!** 🎉\n\u003e\n\u003e Apify has released its MCP ([Model Context Protocol](https://modelcontextprotocol.io)) server, which offers more features. You can use it through the [LangChain MCP Adapter](https://github.com/langchain-ai/langchain-mcp-adapters). It allows you to run Apify Actors, access Apify storage, search and read Apify documentation, and much more.\n\u003e\n\u003e ### 👉 [https://mcp.apify.com](https://mcp.apify.com) 👈\n\n\u003cdiv align=\"center\"\u003e\n\n\u003cpicture\u003e\n  \u003cimg alt=\"Apify logo\" src=\"https://raw.githubusercontent.com/apify/langchain-apify/refs/heads/main/docs/apify-logo.png\" width=\"20%\" height=\"20%\"\u003e\n\u003c/picture\u003e\n\nLangChain Apify: A full-stack scraping platform built on Apify's infrastructure and LangChain's AI tools. Maintained by [Apify](https://apify.com).\n\n\u003ch3\u003e\n\n[Apify](https://apify.com) | [Documentation](https://docs.apify.com/platform/integrations/langchain) | [LangChain](https://langchain.com)\n\n\u003c/h3\u003e\n\n[![GitHub Repo stars](https://img.shields.io/github/stars/apify/langchain-apify)](https://github.com/apify/langchain-apify/stargazers)\n[![Tests](https://github.com/apify/langchain-apify/actions/workflows/run_code_checks.yml/badge.svg)](https://github.com/apify/langchain-apify/actions/workflows/run_code_checks.yml/badge.svg)\n\n\u003c/div\u003e\n\n---\n\nBuild web scraping and automation workflows in Python by connecting Apify Actors with LangChain. This package gives you programmatic access to Apify's infrastructure - run scraping tasks, handle datasets, and use the API directly through LangChain's tools.\n\n## Agentic LLMs\n\nIf you are an agent or an LLM, refer to the [llms.txt](llms.txt) file to get package context and learn how to work with this package.\n\n## Installation\n\n```bash\npip install langchain-apify\n```\n\n## Prerequisites\n\nYou should configure credentials by setting the following environment variables:\n- `APIFY_API_TOKEN` - Apify API token\n\nRegister your free Apify account [here](https://console.apify.com/sign-up) and learn how to get your API token in the [Apify documentation](https://docs.apify.com/platform/integrations/api).\n\n## Tools\n\n`ApifyActorsTool` class provides access to [Apify Actors](https://apify.com/store), which are cloud-based web-scraping and automation programs that you can run without managing any infrastructure. For more detailed information, see the [Apify Actors documentation](https://docs.apify.com/platform/actors).\n\n`ApifyActorsTool` is useful when you need to run an Apify Actor as a tool in LangChain. You can use the tool to interact with the Actor manually or as part of an agent workflow.\n\nExample usage of `ApifyActorsTool` with the [RAG Web Browser](https://apify.com/apify/rag-web-browser) Actor, which searches for information on the web:\n```python\nimport os\nimport json\nfrom langchain_apify import ApifyActorsTool\n\nos.environ[\"OPENAI_API_KEY\"] = \"YOUR_OPENAI_API_KEY\"\nos.environ[\"APIFY_API_TOKEN\"] = \"YOUR_APIFY_API_TOKEN\"\n\nbrowser = ApifyActorsTool('apify/rag-web-browser')\nsearch_results = browser.invoke(input={\n    \"run_input\": {\"query\": \"what is Apify Actor?\", \"maxResults\": 3}\n})\n\n# use the tool with an agent\nfrom langchain_openai import ChatOpenAI\nfrom langgraph.prebuilt import create_react_agent\n\nmodel = ChatOpenAI(model=\"gpt-4o-mini\")\ntools = [browser]\nagent = create_react_agent(model, tools)\n\nfor chunk in agent.stream(\n    {\"messages\": [(\"human\", \"search for what is Apify?\")]},\n    stream_mode=\"values\"\n):\n    chunk[\"messages\"][-1].pretty_print()\n```\n\n## Document loaders\n\n\u003e **⚠️ Note for Actor Developers**: If you're building an Apify Actor, use `Actor.open_dataset()` from the Apify SDK instead of this loader. See the [Note for Apify Actor developers](#note-for-apify-actor-developers) section for details.\n\n`ApifyDatasetLoader` class provides access to [Apify datasets](https://docs.apify.com/platform/storage/dataset) as document loaders. Datasets are storage solutions that store results from web scraping, crawling, or data processing.\n\n`ApifyDatasetLoader` is useful when you need to process data from an Apify Actor run **from outside the Actor runtime** (e.g., in an external script, notebook, or application). If you are extracting webpage content, you would typically use this loader after running an Apify Actor manually from the [Apify console](https://console.apify.com), where you can access the results stored in the dataset.\n\nExample usage for `ApifyDatasetLoader` with a custom dataset mapping function for loading webpage content and source URLs as a list of  `Document` objects containing the page content and source URL.\n```python\nimport os\nfrom langchain_apify import ApifyDatasetLoader\n\nos.environ[\"APIFY_API_TOKEN\"] = \"YOUR_APIFY_API_TOKEN\"\n\n# Example dataset structure\n# [\n#     {\n#         \"text\": \"Example text from the website.\",\n#         \"url\": \"http://example.com\"\n#     },\n#     ...\n# ]\n\nloader = ApifyDatasetLoader(\n    dataset_id=\"your-dataset-id\",\n    dataset_mapping_function=lambda dataset_item: Document(\n        page_content=dataset_item[\"text\"],\n        metadata={\"source\": dataset_item[\"url\"]}\n    ),\n)\n```\n\n## Wrappers\n\n`ApifyWrapper` class wraps the Apify API to easily convert Apify datasets into documents. It is useful when you need to run an Apify Actor programmatically and process the results in LangChain. Available methods include:\n\n- **call_actor**: Runs an Apify Actor and returns an `ApifyDatasetLoader` for the results.\n- **acall_actor**: Asynchronous version of `call_actor`.\n- **call_actor_task**: Runs a saved Actor task and returns an `ApifyDatasetLoader` for the results. Actor tasks allow you to create and reuse multiple configurations of a single Actor for different use cases.\n- **acall_actor_task**: Asynchronous version of `call_actor_task`.\n\nFor more information, see the [Apify LangChain integration documentation](https://docs.apify.com/platform/integrations/langchain).\n\nExample usage for `call_actor` involves running the [Website Content Crawler](https://apify.com/apify/website-content-crawler) Actor, which extracts content from webpages. The wrapper then returns the results as a list of `Document` objects containing the page content and source URL:\n```python\nimport os\nfrom langchain_apify import ApifyWrapper\nfrom langchain_core.documents import Document\n\nos.environ[\"APIFY_API_TOKEN\"] = \"YOUR_APIFY_API_TOKEN\"\n\napify = ApifyWrapper()\n\nloader = apify.call_actor(\n    actor_id=\"apify/website-content-crawler\",\n    run_input={\n        \"startUrls\": [{\"url\": \"https://python.langchain.com/docs/get_started/introduction\"}],\n        \"maxCrawlPages\": 10,\n        \"crawlerType\": \"cheerio\"\n    },\n    dataset_mapping_function=lambda item: Document(\n        page_content=item[\"text\"] or \"\",\n        metadata={\"source\": item[\"url\"]}\n    ),\n)\ndocuments = loader.load()\n```\n\n## Note for Apify Actor developers\n\n**If you are building an Apify Actor that will run on the Apify platform**, you should **NOT** use this package for dataset loading. Instead:\n\n**Use the Apify Actor SDK directly** with `Actor.open_dataset()`\n**Do NOT use** `ApifyDatasetLoader` from this package\n\n### Why?\n\n1. **Security \u0026 permissions**: Actors should run with `LIMITED_PERMISSIONS` and use scoped tokens that grant access only to specific resources. The Actor SDK's `Actor.open_dataset()` method respects these scoped tokens.\n2. **Best practices**: Using the Actor SDK is the proper way to access Apify resources within an Actor runtime environment.\n3. **No external dependencies**: Your Actor doesn't need to depend on `langchain-apify` for basic dataset operations.\n\n### Example: Loading dataset in an Actor\n\n```python\nfrom apify import Actor\nfrom langchain_core.documents import Document\n\nasync def main():\n    async with Actor:\n        # Get dataset ID from input or integration payload\n        dataset_id = Actor.get_input().get(\"datasetId\")\n\n        # Open dataset using Actor SDK (respects LIMITED_PERMISSIONS)\n        dataset = await Actor.open_dataset(name=dataset_id)\n\n        # Transform items to Documents\n        documents = []\n        async for item in dataset.iterate_items():\n            doc = Document(page_content=item.get(\"text\", \"\"), metadata={\"url\": item.get(\"url\")})\n            documents.append(doc)\n```\n\n### When to use langchain-apify\n\nThis package is designed for:\n- External scripts and applications that need to access Apify from outside the Actor runtime\n- LangChain agents that use Apify Actors as tools\n- Data processing pipelines that consume Apify datasets\n\nIt is **NOT** designed for:\n- Code running inside an Apify Actor (use Actor SDK instead)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapify%2Flangchain-apify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapify%2Flangchain-apify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapify%2Flangchain-apify/lists"}