langchain-oxylabs
This package contains the LangChain integration with Oxylabs, providing tools to scrape Google search results with Oxylabs Web Scraper API using LangChain's framework.
Installation
pip install -U langchain-oxylabs
Credentials
Create your API user credentials: Sign up for a free trial or purchase the product in the Oxylabs dashboard to create your API user credentials.
Configure your Oxylabs credentials by setting the following environment variables:
OXYLABS_USERNAME- Your Oxylabs API usernameOXYLABS_PASSWORD- Your Oxylabs API password
Requirements
- Python 3.10 or newer
- Works with both
langchain-core0.3.x and LangChain v1 (langchain-core1.x)
Usage
langchain_oxylabs package provides the following classes:
OxylabsSearchRun- A tool that returns scraped Google search results in a formatted textOxylabsSearchResults- A tool that returns scraped Google search results in a JSON formatOxylabsSearchAPIWrapper- An API wrapper for initializing Oxylabs APIOxylabsLoader- A document loader that scrapes URLs or search queries into LangChainDocumentobjects
Search tools
Here is an example usage of these classes:
import json
from langchain_oxylabs import OxylabsSearchRun, OxylabsSearchResults, OxylabsSearchAPIWrapper
# Initialize the API wrapper
oxylabs_wrapper = OxylabsSearchAPIWrapper()
# Initialize the search run tool
run_tool = OxylabsSearchRun(wrapper=oxylabs_wrapper)
# Invoke the tool and print results
results_text = run_tool.invoke({"query": "Visit restaurants in Vilnius."})
print(results_text)
# Initialize the search results tool
results_tool = OxylabsSearchResults(wrapper=oxylabs_wrapper)
# Invoke the tool and print results
response_results = results_tool.invoke({"query": "Visit restaurants in Paris."})
response_results = json.loads(response_results)
for result in response_results:
for key, value in result.items():
print(f"{key}: {value}")
Geo-targeted results
Pass geo_location to scope results to a location. It can be supplied per call
(an agent may set it from the user's question), or configured once on the wrapper
as a default for every search:
# Per call -- takes precedence
run_tool.invoke({"query": "best coffee", "geo_location": "Vilnius,Lithuania"})
# Or as a default for this wrapper
oxylabs_wrapper = OxylabsSearchAPIWrapper(
params={"geo_location": "Vilnius,Lithuania"}
)
Document loader
OxylabsLoader scrapes content into LangChain Document objects, which makes it
convenient for retrieval-augmented generation. Pass either urls or queries,
plus any Oxylabs Web Scraper API parameters.
from langchain_oxylabs import OxylabsLoader
# Scrape specific URLs as markdown
loader = OxylabsLoader(
urls=[
"https://sandbox.oxylabs.io/products/1",
"https://sandbox.oxylabs.io/products/2",
],
params={"markdown": True},
)
for document in loader.lazy_load():
print(document.metadata)
print(document.page_content[:250])
# Or scrape parsed search results for a list of queries
loader = OxylabsLoader(
queries=["gaming headset", "gaming chair"],
params={
"source": "amazon_search",
"parse": True,
"geo_location": "DE",
"currency": "EUR",
"pages": 3,
},
)
documents = loader.load()
lazy_load() issues one request per URL or query and yields documents as they
arrive, so it is preferable to load() for large batches.
Using with an agent
The search tools work with LangChain's agents. create_agent decides when to
search and with what geo_location:
from langchain.agents import create_agent
from langchain_oxylabs import OxylabsSearchAPIWrapper, OxylabsSearchRun
tool = OxylabsSearchRun(wrapper=OxylabsSearchAPIWrapper())
agent = create_agent(model="anthropic:claude-sonnet-5", tools=[tool])
result = agent.invoke(
{"messages": [{"role": "user", "content": "Find good coffee in Vilnius"}]}
)
print(result["messages"][-1].content)
Development
poetry install --with test,lint,typing
make test # unit tests, no network access
make lint # ruff + mypy
make integration_tests # live API calls, requires credentials
License
This project is licensed under the MIT License - see the LICENSE file for details.
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_oxylabs-0.3.0.tar.gz.
File metadata
- Download URL: langchain_oxylabs-0.3.0.tar.gz
- Upload date:
- Size: 15.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
poetry/2.1.3 CPython/3.13.3 Darwin/25.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d7f5080a2030b8d83f9332e25d79665605999a5a69c98028fec63febeba7696
|
|
| MD5 |
adf3a3b66af8b23e178400ed94b526ca
|
|
| BLAKE2b-256 |
be101afb19c8df88c0c926a11370c643771d9e329159d5484c560ebc267bd6eb
|
File details
Details for the file langchain_oxylabs-0.3.0-py3-none-any.whl.
File metadata
- Download URL: langchain_oxylabs-0.3.0-py3-none-any.whl
- Upload date:
- Size: 16.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
poetry/2.1.3 CPython/3.13.3 Darwin/25.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f216db36da95eaa0c15527e35437f2d09e263a6f8c97cad8a3f287e2b1186909
|
|
| MD5 |
3089bf414afa48fafb44f5c7d63033c8
|
|
| BLAKE2b-256 |
27704da451570ab8772feaabb7539c0288d516f106d0e3e4dc77affacc7e49a6
|