Skip to main content

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.

YouTube

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 username
  • OXYLABS_PASSWORD - Your Oxylabs API password

Requirements

  • Python 3.10 or newer
  • Works with both langchain-core 0.3.x and LangChain v1 (langchain-core 1.x)

Usage

langchain_oxylabs package provides the following classes:

  • OxylabsSearchRun - A tool that returns scraped Google search results in a formatted text
  • OxylabsSearchResults - A tool that returns scraped Google search results in a JSON format
  • OxylabsSearchAPIWrapper - An API wrapper for initializing Oxylabs API
  • OxylabsLoader - A document loader that scrapes URLs or search queries into LangChain Document objects

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

langchain_oxylabs-0.3.0.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_oxylabs-0.3.0-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

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

Hashes for langchain_oxylabs-0.3.0.tar.gz
Algorithm Hash digest
SHA256 4d7f5080a2030b8d83f9332e25d79665605999a5a69c98028fec63febeba7696
MD5 adf3a3b66af8b23e178400ed94b526ca
BLAKE2b-256 be101afb19c8df88c0c926a11370c643771d9e329159d5484c560ebc267bd6eb

See more details on using hashes here.

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

Hashes for langchain_oxylabs-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f216db36da95eaa0c15527e35437f2d09e263a6f8c97cad8a3f287e2b1186909
MD5 3089bf414afa48fafb44f5c7d63033c8
BLAKE2b-256 27704da451570ab8772feaabb7539c0288d516f106d0e3e4dc77affacc7e49a6

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page