Skip to main content

Oxylabs Search Run

Overview​

This notebook goes over how to use the Oxylabs search run component.

Integration details​

ClassPackage
OxylabsSearchRunlangchain-community

Tool features​

Returns artifactPricing
âś…Free 5,000 results for 1 week

Setup​

The integration lives in the langchain-community package. We also need to install the oxylabs package.

%pip install -U langchain-community oxylabs

Credentials​

Set up the proper API keys and environment variables.
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 (OXYLABS_USERNAME and OXYLABS_PASSWORD).

import getpass
import os

os.environ["OXYLABS_USERNAME"] = getpass.getpass()
os.environ["OXYLABS_PASSWORD"] = getpass.getpass()

Instantiation​

from langchain_community.tools.oxylabs_search import OxylabsSearchRun
from langchain_community.utilities import OxylabsSearchAPIWrapper

oxylabs_wrapper = OxylabsSearchAPIWrapper()
tool_ = OxylabsSearchRun(wrapper=oxylabs_wrapper)

Invocation​

Invoke directly with args​

The OxylabsSearchRun tool takes a single "query" argument,
which should be a natural language query and returns combined string format result:

tool_.invoke({"query": "Visit restaurants in Vilnius."})
"  ORGANIC RESULTS ITEMS: \n    ORGANIC-ITEM-1: \n    POS: 1\n    URL: https://www.tripadvisor.com/Restaurants-g274951-Vilnius_Vilnius_County.html\n    DESC: Some of the best restaurants in Vilnius for families with children include: Momo grill Vilnius · Jurgis ir Drakonas Ogmios · RoseHip Vegan\xa0...\n    TITLE: THE 10 BEST Restaurants in Vilnius (Updated November ...\n    SITELINKS: \n      SITELINKS: \n      INLINE ITEMS: \n        INLINE-ITEM-1: \n        URL: https://www.tripadvisor.com/Restaurants-g274951-zfp58-Vilnius_Vilnius_County.html\n        TITLE: Vilnius Dinner Restaurants\n        INLINE-ITEM-2: \n        URL: https://www.tripadvisor.com/Restaurants-g274951-zfp2-Vilnius_Vilnius_County.html\n        TITLE: Vilnius Breakfast Restaurants\n        INLINE-ITEM-3: \n        URL: https://www.tripadvisor.com/Restaurants-g274951-c8-Vilnius_Vilnius_County.html\n        TITLE: Cafés in Vilnius\n    URL_SHOWN: https://www.tripadvisor.com › ... › Vilnius\n    FAVICON_TEXT: Tripadvisor\n    ORGANIC-ITEM-2: \n    POS: 2\n    URL: https://www.amsterdamfoodie.nl/2022/foodie-guide-to-vilnius-lithuania/\n    DESC: Dec 2, 2022 — Vilnius takes the top spot for most creative dining with the fabulous restaurant Amandus. Modern gastronomy, with a nod to Lithuanian tradition, goes hand in\xa0...\n    TITLE: A Foodie's Guide to Vilnius, Lithuania\n    URL_SHOWN: https://www.amsterdamfoodie.nl › blog\n    FAVICON_TEXT: Amsterdam Foodie\n    ORGANIC-ITEM-3: \n    POS: 3\n    URL: https://theweek.com/culture-life/food-drink/foodie-guide-to-vilnius-lithuania\n    DESC: Jun 24, 2024 — Lithuania's capital has established itself as an affordable culinary hotspot as four of the city's restaurants awarded Michelin stars.\n    TITLE: Star quality: a foodie guide to Vilnius\n    SITELINKS: \n      SITELINKS: \n      INLINE ITEMS: \n        INLINE-ITEM-1: \n        URL: https://theweek.com/culture-life/food-drink/foodie-guide-to-vilnius-lithuania#:~:text=Nineteen18,-With%20its%20%60%60sleek%20and\n        TITLE: Nineteen18\n        INLINE-ITEM-2: \n        URL: https://theweek.com/culture-life/food-drink/foodie-guide-to-vilnius-lithuania#:~:text=D%C5%BEiaugsmas,-D%C5%BEiaugsmas\n        TITLE: Džiaugsmas\n        INLINE-ITEM-3: \n        URL: https://theweek.com/culture-life/food-drink/foodie-guide-to-vilnius-lithuania#:~:text=Gaspar%27s\n        TITLE: Gaspar's\n    URL_SHOWN: https://theweek.com › Culture & Life › Food & Drink\n    FAVICON_TEXT: The Week\n    ORGANIC-ITEM-4: \n    POS: 4\n    URL: https://www.reddit.com/r/Vilnius/comments/13049t3/vilnius_restaurants_suggestions_please/\n    DESC: I like eating at Bernelių Užeiga. Serves authentic Lithuanian food though it is a little bit commercialised I still usually enjoy the food very\xa0...\n    TITLE: Vilnius restaurants suggestions please?\n    URL_SHOWN: 8 comments  ·  1 year ago\n    FAVICON_TEXT: Reddit\xa0·\xa0r/Vilnius\n\n  LOCAL PACK: \n  ITEMS ITEMS: \n    ITEMS-ITEM-1: \n    CID: 13950149882539119249\n    POS: 1\n    TITLE: Etno Dvaras\n    RATING: 4.5\n    ADDRESS: Lithuanian\n    ITEMS-ITEM-2: \n    CID: 711702509070991018\n    POS: 2\n    TITLE: Lokys\n    RATING: 4.5\n    ADDRESS: Lithuanian\n    ITEMS-ITEM-3: \n    CID: 7630589473191639738\n    POS: 3\n    TITLE: Senoji trobelė\n    RATING: 4.4\n    ADDRESS: Lithuanian\n\n  SEARCH INFORMATION: \n  QUERY: Visit restaurants in Vilnius.\n  GEO_LOCATION: United States\n  SHOWING_RESULTS_FOR: Visit restaurants in Vilnius.\n  TOTAL_RESULTS_COUNT: 1210000\n\n  RELATED SEARCHES: \n  RELATED_SEARCHES ITEMS: \n    RELATED_SEARCHES-ITEM-1: Best restaurants in Vilnius old town\n    RELATED_SEARCHES-ITEM-2: Unique places to eat in Vilnius\n    RELATED_SEARCHES-ITEM-3: Best visit restaurants in vilnius\n    RELATED_SEARCHES-ITEM-4: Best Lithuanian restaurants in Vilnius\n    RELATED_SEARCHES-ITEM-5: Restaurants Vilnius old Town\n    RELATED_SEARCHES-ITEM-6: Vilnius restaurants Michelin\n    RELATED_SEARCHES-ITEM-7: Fine dining Vilnius\n    RELATED_SEARCHES-ITEM-8: Tripadvisor Vilnius Restaurants"

Invoke with ToolCall​

tool_ = OxylabsSearchRun(
wrapper=oxylabs_wrapper,
kwargs={
"result_categories": [
"local_information",
"combined_search_result",
]
},
)
from pprint import pprint

model_generated_tool_call = {
"args": {
"query": "Visit restaurants in Vilnius.",
"geo_location": "Vilnius,Lithuania",
},
"id": "1",
"name": "oxylabs_search",
"type": "tool_call",
}
tool_call_result = tool_.invoke(model_generated_tool_call)

# The content is a JSON string of results
pprint(tool_call_result.content)
('  LOCAL PACK: \n'
' ITEMS ITEMS: \n'
' ITEMS-ITEM-1: \n'
' CID: 13950149882539119249\n'
' POS: 1\n'
' TITLE: Etno Dvaras\n'
' RATING: 4.5\n'
' ADDRESS: Lithuanian\n'
' ITEMS-ITEM-2: \n'
' CID: 711702509070991018\n'
' POS: 2\n'
' TITLE: Lokys\n'
' RATING: 4.5\n'
' ADDRESS: Lithuanian\n'
' ITEMS-ITEM-3: \n'
' CID: 7630589473191639738\n'
' POS: 3\n'
' TITLE: Senoji trobelÄ—\n'
' RATING: 4.4\n'
' ADDRESS: Lithuanian\n'
'\n'
' ORGANIC RESULTS ITEMS: \n'
' ORGANIC-ITEM-1: \n'
' POS: 1\n'
' URL: '
'https://www.tripadvisor.com/Restaurants-g274951-Vilnius_Vilnius_County.html\n'
' DESC: Some of the best restaurants in Vilnius for families with children '
'include: Momo grill Vilnius · Jurgis ir Drakonas Ogmios · RoseHip Vegan\xa0'
'...\n'
' TITLE: THE 10 BEST Restaurants in Vilnius (Updated November ...\n'
' SITELINKS: \n'
' SITELINKS: \n'
' INLINE ITEMS: \n'
' INLINE-ITEM-1: \n'
' URL: '
'https://www.tripadvisor.com/Restaurants-g274951-zfp58-Vilnius_Vilnius_County.html\n'
' TITLE: Vilnius Dinner Restaurants\n'
' INLINE-ITEM-2: \n'
' URL: '
'https://www.tripadvisor.com/Restaurants-g274951-zfp2-Vilnius_Vilnius_County.html\n'
' TITLE: Vilnius Breakfast Restaurants\n'
' INLINE-ITEM-3: \n'
' URL: '
'https://www.tripadvisor.com/Restaurants-g274951-c8-Vilnius_Vilnius_County.html\n'
' TITLE: Cafés in Vilnius\n'
' URL_SHOWN: https://www.tripadvisor.com› ... › Vilnius\n'
' FAVICON_TEXT: Tripadvisor\n'
' ORGANIC-ITEM-2: \n'
' POS: 2\n'
' URL: '
'https://theweek.com/culture-life/food-drink/foodie-guide-to-vilnius-lithuania\n'
" DESC: Jun 24, 2024 — Lithuania's capital has established itself as an "
"affordable culinary hotspot as four of the city's restaurants awarded "
'Michelin stars.\n'
' TITLE: Star quality: a foodie guide to Vilnius\n'
' URL_SHOWN: https://theweek.com› Culture & Life › Food & Drink\n'
' FAVICON_TEXT: The Week\n'
' ORGANIC-ITEM-3: \n'
' POS: 3\n'
' URL: https://www.govilnius.lt/visit-vilnius/restaurants2\n'
' DESC: Visit local restaurants in Vilnius and have a gastronomic '
'experience ... Vilnius offers many unconventional places for a hearty and '
'inexpensive lunch.\n'
' TITLE: Restaurants\n'
' URL_SHOWN: https://www.govilnius.lt› visit-vilnius › restaurants2\n'
' FAVICON_TEXT: Go Vilnius\n'
' ORGANIC-ITEM-4: \n'
' POS: 4\n'
' URL: '
'https://www.reddit.com/r/Vilnius/comments/uudd1p/good_restaurants_street_food_in_vilnius/\n'
' DESC: - AlinÄ— LeiÄŤiai - also traditional peasant food of history but in '
'a more upscale environment, and more expensive, table service and more '
'diverse\xa0...\n'
' TITLE: Good restaurants & street food in Vilnius?\n'
' URL_SHOWN: 10+ comments · 2 years ago\n'
' FAVICON_TEXT: Reddit\xa0·\xa0r/Vilnius')

Chaining​

# Install the required libraries
%pip install --upgrade --quiet langchain langchain-openai
%pip install langchainhub langchain-community
import getpass
import os

from langchain import hub
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_openai import ChatOpenAI

# Set up OpenAI API credentials
os.environ["OPENAI_API_KEY"] = getpass.getpass("Enter your OpenAI API key: ")

# Define assistant instructions and pull a base prompt template
instructions = """You are an assistant."""
base_prompt = hub.pull("langchain-ai/openai-functions-template")
prompt = base_prompt.partial(instructions=instructions)

# Initialize OpenAI chat model
llm = ChatOpenAI(openai_api_key=os.environ["OPENAI_API_KEY"])

# Define tools and agent setup
tool_ = OxylabsSearchRun(wrapper=oxylabs_wrapper)
tools_ = [tool_]
agent = create_tool_calling_agent(llm, tools_, prompt)

# Set up and invoke the agent executor
agent_executor = AgentExecutor(
agent=agent,
tools=tools_,
verbose=True,
)
agent_executor.invoke({"input": "What happened in the latest Burning Man floods?"})
/home/ausra/Data/AMV-workspace/projects_review/Oxylabs/langchain-project/.venv/lib/python3.11/site-packages/langsmith/client.py:354: LangSmithMissingAPIKeyWarning: API key must be provided when using hosted LangSmith API
warnings.warn(
``````output


> Entering new AgentExecutor chain...
``````output
INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK"
``````output

Invoking: `oxylabs_search` with `{'query': 'latest Burning Man floods news'}`


 ORGANIC RESULTS ITEMS:
ORGANIC-ITEM-1:
POS: 1
URL: https://abcnews.go.com/US/burning-man-flooding-happened-stranded-festivalgoers/story?id=102908331
DESC: Sep 4, 2023 — Tens of thousands of Burning Man attendees are now able to leave the festival after a downpour and massive flooding left them stranded over the weekend.
TITLE: Burning Man flooding: What happened to stranded ...
URL_SHOWN: https://abcnews.go.com› story
FAVICON_TEXT: ABC News - Breaking News, Latest News and Videos
ORGANIC-ITEM-2:
POS: 2
URL: https://www.outsideonline.com/outdoor-adventure/exploration-survival/burning-man-2023-flooding-rain/
DESC: Sep 6, 2023 — When storms left Burning Man 2023 a muddy mess, attendees plotted their way out.
TITLE: How One Man Escaped From Burning Man 2023's Floods
URL_SHOWN: https://www.outsideonline.com› exploration-survival
FAVICON_TEXT: Outside Magazine
ORGANIC-ITEM-3:
POS: 3
URL: https://www.foxweather.com/weather-news/burning-man-festivalgoers-experience-travel-issues-black-rock-city-nevada-rain
DESC: Aug 24, 2024 — Monsoon rains on Friday and over the weekend caused flash flooding at Burning Man, turning the usually dry, desert landscape of the festival ...
TITLE: Travel to Burning Man delayed due to thunderstorms
URL_SHOWN: https://www.foxweather.com› weather-news › burning...
FAVICON_TEXT: FOX Weather
ORGANIC-ITEM-4:
POS: 4
URL: https://www.nbcnews.com/news/us-news/live-blog/live-updates-burning-man-flooding-keeps-thousands-stranded-nevada-site-rcna103193
DESC: Sep 4, 2023 — Burning Man flooding keeps thousands stranded at Nevada site as authorities investigate 1 death. Attendees at the countercultural music and arts ...
TITLE: Burning Man flooding keeps thousands stranded at ...
URL_SHOWN: https://www.nbcnews.com› news › us-news › live-blog
FAVICON_TEXT: NBC News

ORGANIC VIDEOS ITEMS:
ORGANIC_VIDEOS-ITEM-1:
POS: 1
URL: https://www.youtube.com/watch?v=a1xBz6g1Kc8
DESC: Thousands leaving Burning Man festival after flooding from heavy rain Thousands of people are leaving Burning Man after torrential rain ...
TITLE: Thousands leaving Burning Man festival after flooding from ...

SEARCH INFORMATION:
QUERY: latest Burning Man floods news
GEO_LOCATION: United States
SHOWING_RESULTS_FOR: latest Burning Man floods news
TOTAL_RESULTS_COUNT: 33100000

RELATED SEARCHES:
RELATED_SEARCHES ITEMS:
RELATED_SEARCHES-ITEM-1: Latest burning man floods news today
RELATED_SEARCHES-ITEM-2: Latest burning man floods news nevada
RELATED_SEARCHES-ITEM-3: Burning Man 2023 Flood pictures
RELATED_SEARCHES-ITEM-4: Burning Man 2023 flood death
RELATED_SEARCHES-ITEM-5: Burning Man flood 2024
RELATED_SEARCHES-ITEM-6: Flooded Festival 2024
RELATED_SEARCHES-ITEM-7: Burning Man 2024
RELATED_SEARCHES-ITEM-8: Burning Man tickets
``````output
INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK"
``````output
In the latest Burning Man floods, tens of thousands of attendees were stranded at the festival due to a downpour and massive flooding. The flooding caused travel issues and delays for festivalgoers, turning the usually dry desert landscape into a muddy mess. Authorities were investigating one death related to the flooding. Attendees had to plot their way out of the flooded area. Thousands of people are now leaving Burning Man after the torrential rain. If you would like more detailed information, you can visit the following sources for news coverage:

1. [ABC News: Burning Man flooding - What happened to stranded festivalgoers](https://abcnews.go.com/US/burning-man-flooding-happened-stranded-festivalgoers/story?id=102908331)
2. [Outside Online: How One Man Escaped From Burning Man 2023's Floods](https://www.outsideonline.com/outdoor-adventure/exploration-survival/burning-man-2023-flooding-rain/)
3. [FOX Weather: Travel to Burning Man delayed due to thunderstorms](https://www.foxweather.com/weather-news/burning-man-festivalgoers-experience-travel-issues-black-rock-city-nevada-rain)
4. [NBC News: Burning Man flooding keeps thousands stranded at Nevada site](https://www.nbcnews.com/news/us-news/live-blog/live-updates-burning-man-flooding-keeps-thousands-stranded-nevada-site-rcna103193)

> Finished chain.
{'input': 'What happened in the latest Burning Man floods?',
'output': "In the latest Burning Man floods, tens of thousands of attendees were stranded at the festival due to a downpour and massive flooding. The flooding caused travel issues and delays for festivalgoers, turning the usually dry desert landscape into a muddy mess. Authorities were investigating one death related to the flooding. Attendees had to plot their way out of the flooded area. Thousands of people are now leaving Burning Man after the torrential rain. If you would like more detailed information, you can visit the following sources for news coverage:\n\n1. [ABC News: Burning Man flooding - What happened to stranded festivalgoers](https://abcnews.go.com/US/burning-man-flooding-happened-stranded-festivalgoers/story?id=102908331)\n2. [Outside Online: How One Man Escaped From Burning Man 2023's Floods](https://www.outsideonline.com/outdoor-adventure/exploration-survival/burning-man-2023-flooding-rain/)\n3. [FOX Weather: Travel to Burning Man delayed due to thunderstorms](https://www.foxweather.com/weather-news/burning-man-festivalgoers-experience-travel-issues-black-rock-city-nevada-rain)\n4. [NBC News: Burning Man flooding keeps thousands stranded at Nevada site](https://www.nbcnews.com/news/us-news/live-blog/live-updates-burning-man-flooding-keeps-thousands-stranded-nevada-site-rcna103193)"}
agent_executor.invoke(
{"input": "What is the most profitable company in Lithuania in 2024?"}
)


> Entering new AgentExecutor chain...
``````output
INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK"
``````output

Invoking: `oxylabs_search` with `{'query': 'most profitable company in Lithuania in 2024'}`


 ORGANIC RESULTS ITEMS:
ORGANIC-ITEM-1:
POS: 1
URL: https://ceoworld.biz/2024/02/19/lithuanias-largest-companies-by-market-capitalization-2024/
DESC: Feb 19, 2024 — As of October 24, 2024, AB IGNITIS GRUPE is the most valuable company in Lithuania, with a market cap of $1.51 billion. Following it are TELIA ...
TITLE: Lithuania's Largest Companies by market capitalization, ...
URL_SHOWN: https://ceoworld.biz› Latest › Banking and Finance
FAVICON_TEXT: CEOWORLD magazine
ORGANIC-ITEM-2:
POS: 2
URL: https://lithuania.lt/news/business-and-innovations-in-lithuania/which-startups-will-be-making-waves-in-lithuania-in-2024/
DESC: Jan 23, 2024 — Which startups will be making waves in Lithuania in 2024? · Which startups are worth keeping an eye on in 2024? · 1. Cast AI: · 2. Amlyze: · 3.
TITLE: Which startups will be making waves in Lithuania in 2024?
URL_SHOWN: https://lithuania.lt› News
FAVICON_TEXT: lithuania.lt
ORGANIC-ITEM-3:
POS: 3
URL: https://www.f6s.com/companies/lithuania/lo
DESC: Oct 24, 2024 — Detailed info and reviews on 100 top companies and startups in Lithuania in 2024. Get the latest updates on their products, jobs, funding, ...
TITLE: 100 top Companies and Startups in Lithuania in October ...
URL_SHOWN: https://www.f6s.com› companies › lithuania
FAVICON_TEXT: F6S
ORGANIC-ITEM-4:
POS: 4
URL: https://www.failory.com/startups/lithuania
DESC: Here's an extensive list with the 76 best startups in Lithuania and their main information.
TITLE: Top 76 Startups in Lithuania in 2024
SITELINKS:
SITELINKS:
INLINE ITEMS:
INLINE-ITEM-1:
URL: https://www.failory.com/startups/lithuania#76-startups-in-lithuania
TITLE: Startups in Lithuania
INLINE-ITEM-2:
URL: https://www.failory.com/startups/lithuania#3-affise
TITLE: 3) Affise
INLINE-ITEM-3:
URL: https://www.failory.com/startups/lithuania#4-trafi
TITLE: 4) Trafi
INLINE-ITEM-4:
URL: https://www.failory.com/startups/lithuania#8-ziticity
TITLE: 8) ZITICITY
URL_SHOWN: https://www.failory.com› startups › lithuania
FAVICON_TEXT: Failory
ORGANIC-ITEM-5:
POS: 5
URL: https://bebeez.eu/2024/04/02/these-8-startups-secured-the-largest-lithuanian-funding-rounds-in-q1-2024-some-are-now-hiring/
DESC: Apr 2, 2024 — These 8 startups secured the largest Lithuanian funding rounds in Q1 2024; some are now hiring. Silicon Canals bySilicon Canals · April 2, 2024.
TITLE: These 8 startups secured the largest Lithuanian funding ...
URL_SHOWN: https://bebeez.eu› 2024/04/02 › these-8-startups-secure...
FAVICON_TEXT: BeBeez International

SEARCH INFORMATION:
QUERY: most profitable company in Lithuania in 2024
GEO_LOCATION: United States
SHOWING_RESULTS_FOR: most profitable company in Lithuania in 2024
TOTAL_RESULTS_COUNT: 49000000

RELATED SEARCHES:
RELATED_SEARCHES ITEMS:
RELATED_SEARCHES-ITEM-1: Top 10 most profitable company in lithuania in 2024
RELATED_SEARCHES-ITEM-2: Top 20 most profitable company in lithuania in 2024
RELATED_SEARCHES-ITEM-3: Most profitable company in lithuania in 2024 by revenue
RELATED_SEARCHES-ITEM-4: Most profitable company in lithuania in 2024 in us
RELATED_SEARCHES-ITEM-5: International companies in Lithuania
RELATED_SEARCHES-ITEM-6: Biggest Lithuanian companies
RELATED_SEARCHES-ITEM-7: Top 10 companies in Lithuania
RELATED_SEARCHES-ITEM-8: IT companies in Lithuania
``````output
INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK"
``````output
The most valuable company in Lithuania in 2024 is AB IGNITIS GRUPE, with a market capitalization of $1.51 billion as of October 24, 2024.

> Finished chain.
{'input': 'What is the most profitable company in Lithuania in 2024?',
'output': 'The most valuable company in Lithuania in 2024 is AB IGNITIS GRUPE, with a market capitalization of $1.51 billion as of October 24, 2024.'}

API reference​

For detailed documentation of all OxylabsSearchRun features and configurations head to the API reference: https://python.langchain.com/api_reference/community/tools/langchain_community.tools.oxylabs_search.tool.OxylabsSearchRun.html


Was this page helpful?