An integration package connecting You.com and LangChain
Project description
langchain-youdotcom
LangChain partner package for You.com search and content APIs.
Installation
pip install -U langchain-youdotcom
Credentials
Get an API key at you.com/platform/api-keys, then set it as an environment variable:
export YDC_API_KEY="your-api-key"
Or pass it directly when instantiating any component:
retriever = YouRetriever(ydc_api_key="your-api-key")
Retriever
The simplest way to get You.com search results as LangChain documents.
from langchain_youdotcom import YouRetriever
retriever = YouRetriever()
docs = retriever.invoke("latest AI news")
for doc in docs:
print(doc.metadata["title"])
print(doc.page_content[:200])
print()
All search parameters are available directly on the retriever:
retriever = YouRetriever(
k=5, # max documents to return
count=10, # max results per API section
livecrawl="web", # fetch live page content
livecrawl_formats="markdown",
country="US",
freshness="week", # day, week, month, year
safesearch="moderate", # off, moderate, strict
)
Tools
YouSearchTool
Search the web with You.com. Works with any LangChain agent.
from langchain_youdotcom import YouSearchTool
tool = YouSearchTool()
result = tool.invoke("what is retrieval augmented generation")
print(result)
YouContentsTool
Fetch and extract content from web pages.
from langchain_youdotcom import YouContentsTool
tool = YouContentsTool()
result = tool.invoke({"urls": ["https://example.com"]})
print(result)
Using with an agent
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
from langchain_youdotcom import YouSearchTool
tools = [YouSearchTool()]
agent = create_react_agent(ChatOpenAI(model="gpt-4o"), tools)
response = agent.invoke(
{"messages": [{"role": "user", "content": "what happened in AI today?"}]}
)
YouSearchAPIWrapper
For more control, use the wrapper directly. It powers the retriever and tools under the hood.
from langchain_youdotcom import YouSearchAPIWrapper
wrapper = YouSearchAPIWrapper()
# search -> list[Document]
docs = wrapper.results("latest AI news")
# raw SDK response
raw = wrapper.raw_results("latest AI news")
# contents API -> list[Document]
pages = wrapper.contents(
["https://example.com"],
formats=["markdown", "metadata"],
)
Async variants are available as results_async, raw_results_async, and contents_async.
Documentation
Development
uv sync --all-groups
make format # ruff format + fix
make lint # ruff check + format diff + mypy
make test # unit tests
make integration_tests # requires YDC_API_KEY
make check_imports # verify all modules importable
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_youdotcom-0.1.0.tar.gz.
File metadata
- Download URL: langchain_youdotcom-0.1.0.tar.gz
- Upload date:
- Size: 97.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54c91794d5f1e20c2ec2f193004038ba99903f3090e69669c65f573bb9089e64
|
|
| MD5 |
a26761014af481b4931a86bdf12b4539
|
|
| BLAKE2b-256 |
da76977860526ca964165e24c4e57c7797ccf25ed35e3ef26e56e165e190f875
|
File details
Details for the file langchain_youdotcom-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_youdotcom-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0454331bfae9d26c2c4241bf6570a83adde6bab37db0b3300d4364dac5824e3
|
|
| MD5 |
659f6d3917851d968053c9e9b77849d1
|
|
| BLAKE2b-256 |
e8bdc7f80010979218b1efbf30cab343cb958f5d59cc3430f95f5313bbbc4294
|