LangChain integration for Bright Data's web data APIs
Installation • Quick Start • Tools • Configuration • Resources
langchain-brightdata provides LangChain tools for Bright Data's web data APIs, enabling your AI agents to:
- Search - Query search engines with geo-targeting and language customization
- Fetch - Read any web page, including bot-protected ones
- Scrape - Extract structured data from Amazon, LinkedIn, and 100+ domains
- Search scrapers - Look up the ready-made scraper for a site and the inputs it needs
pip install langchain-brightdataRequirements: Python 3.9+
Sign up at Bright Data and get your API key from the dashboard.
import os
os.environ["BRIGHT_DATA_API_KEY"] = "your-api-key"Or pass it directly:
from langchain_brightdata import BrightDataSERP
tool = BrightDataSERP(bright_data_api_key="your-api-key")from langchain_brightdata import BrightDataSERP, BrightDataWebFetch, BrightDataWebScraperAPI
from langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI
# Initialize tools
tools = [
BrightDataSERP(),
BrightDataWebFetch(),
BrightDataWebScraperAPI()
]
# Create agent
llm = ChatOpenAI(model="gpt-4")
agent = initialize_agent(tools, llm, agent=AgentType.OPENAI_FUNCTIONS)
# Run
agent.run("Search for the latest AI news and summarize the top result")Search engine results with geo-targeting and customization.
from langchain_brightdata import BrightDataSERP
serp = BrightDataSERP()
# Simple search
results = serp.invoke("latest AI research")
# Advanced search
results = serp.invoke({
"query": "electric vehicles",
"country": "de",
"language": "de",
"search_type": "nws"
})| Parameter | Type | Default | Description |
|---|---|---|---|
query |
str | required | Search query |
search_engine |
str | "google" |
Search engine (google or bing) |
country |
str | "us" |
Two-letter country code. On Bing it is followed most of the time, not always |
language |
str | "en" |
Language code. Google only in practice: Bing answers in the language of the country |
search_type |
str | None |
Google only. None (web), "isch" (images), "shop", "nws" (news), "jobs" |
device_type |
str | None |
None (desktop), "mobile", "ios", "android" |
parse_results |
bool | True |
Structured JSON. False returns the raw HTML page |
Each search returns about 10 results. results_count no longer does anything, because Google and Bing stopped letting a request choose the number of results. It is still accepted so existing code keeps working, and will be removed in 0.4.0.
Read one web page, including pages that block ordinary requests. It needs only an API key: no zone is used or created.
from langchain_brightdata import BrightDataWebFetch
fetch = BrightDataWebFetch()
# Markdown by default
content = fetch.invoke({"url": "https://example.com"})
# Plain text or the page source
content = fetch.invoke({"url": "https://example.com", "format": "text"})A page that cannot be read comes back as an error, never as page content. The error names the URL and carries what Bright Data replied, as it was sent:
Could not read https://example.com/missing: The navigation resulted in a dead page (404 status code) (dead_page)
Could not read https://example.com (Bright Data replied: HTTP 401: Invalid credentials).
Most pages come back in a few seconds. A slow page is waited for up to 120 seconds; then the error carries Bright Data's last reply. To change the limit, set it when creating the tool:
fetch = BrightDataWebFetch(timeout=180)If Bright Data answers HTTP 502 (a server error on its side), the tool asks once more.
Bright Data answers "still working" only after about a minute, so a limit under 75 seconds leaves no time to follow a slow page. No request is sent after the limit; one that is already on its way can end a moment later.
| Parameter | Type | Default | Description |
|---|---|---|---|
url |
str | required | Full URL of the page to read |
format |
str | "markdown" |
"markdown", "text" (plain text) or "html" (page source) |
BrightDataUnlocker was removed. Use BrightDataWebFetch instead.
Find the ready-made Bright Data scraper for a site, and the inputs it needs. It only finds scrapers. It does not run them. It reads Bright Data's public scraper catalogue, so it needs no API key and sends none.
from langchain_brightdata import BrightDataSearchScrapers
search_scrapers = BrightDataSearchScrapers()
found = search_scrapers.invoke({"query": "amazon products", "limit": 1})Use 1 to 3 simple keywords: a site name and a data type. The answer is one JSON string, best match first (shortened here to one of the five methods):
{"query": "amazon products", "results": [{"id": "gd_l7q7dkf244hwjntr0", "name": "Amazon products", "site": "amazon.com", "methods": [{"method": "collect_by_url", "required": ["url"], "optional": 5}]}], "unmatched_words": []}Each method lists its required inputs by name and counts the optional ones. unmatched_words holds the query words that no scraper mentions. A misspelled site name is repaired and reported, as "corrections": {"linkedn": "linkedin"}. A pasted URL or domain is searched by its site name.
When there is something to say, a note comes right after query, before the results: no match, a word no scraper mentions, a corrected spelling, or inputs that could not be loaded (required is then null). limit is 1 to 10, default 5. The catalogue and the inputs of each returned scraper are kept in memory for 24 hours, so a repeated search sends no request. Loading inputs stops after 20 seconds in one search.
Extract structured data from popular websites.
from langchain_brightdata import BrightDataWebScraperAPI
scraper = BrightDataWebScraperAPI()
# Amazon product
product = scraper.invoke({
"url": "https://www.amazon.com/dp/B08L5TNJHG",
"dataset_type": "amazon_product"
})
# LinkedIn profile
profile = scraper.invoke({
"url": "https://www.linkedin.com/in/satyanadella/",
"dataset_type": "linkedin_person_profile"
})| Parameter | Type | Default | Description |
|---|---|---|---|
url |
str | required | URL to scrape |
dataset_type |
str | required | Type of data to extract |
zipcode |
str | None |
Zipcode for location-specific data |
E-Commerce (10 datasets)
| Type | Description | Required Inputs |
|---|---|---|
amazon_product |
Product details, pricing, specs | url (with /dp/) |
amazon_product_reviews |
Customer reviews and ratings | url (with /dp/) |
amazon_product_search |
Search results from Amazon | keyword, url |
walmart_product |
Walmart product data | url (with /ip/) |
walmart_seller |
Walmart seller information | url |
ebay_product |
eBay product data | url |
homedepot_products |
Home Depot product data | url |
zara_products |
Zara product data | url |
etsy_products |
Etsy product data | url |
bestbuy_products |
Best Buy product data | url |
LinkedIn (5 datasets)
| Type | Description | Required Inputs |
|---|---|---|
linkedin_person_profile |
Professional profile data | url |
linkedin_company_profile |
Company information | url |
linkedin_job_listings |
Job listing details | url |
linkedin_posts |
Post content and engagement | url |
linkedin_people_search |
Search for people | url, first_name, last_name |
Business Intelligence (2 datasets)
| Type | Description | Required Inputs |
|---|---|---|
crunchbase_company |
Company funding, investors, metrics | url |
zoominfo_company_profile |
B2B company intelligence | url |
Instagram (4 datasets)
| Type | Description | Required Inputs |
|---|---|---|
instagram_profiles |
Profile data and stats | url |
instagram_posts |
Post content and engagement | url |
instagram_reels |
Reel content and metrics | url |
instagram_comments |
Comments on posts | url |
Facebook (4 datasets)
| Type | Description | Required Inputs |
|---|---|---|
facebook_posts |
Post content and engagement | url |
facebook_marketplace_listings |
Marketplace listing data | url |
facebook_company_reviews |
Company reviews | url, num_of_reviews |
facebook_events |
Event details | url |
TikTok (4 datasets)
| Type | Description | Required Inputs |
|---|---|---|
tiktok_profiles |
Profile data and stats | url |
tiktok_posts |
Video content and metrics | url |
tiktok_shop |
Shop product data | url |
tiktok_comments |
Comments on videos | url |
YouTube (3 datasets)
| Type | Description | Required Inputs |
|---|---|---|
youtube_profiles |
Channel profile data | url |
youtube_videos |
Video content and metrics | url |
youtube_comments |
Comments on videos | url, num_of_comments (default: 10) |
Google (3 datasets)
| Type | Description | Required Inputs |
|---|---|---|
google_maps_reviews |
Business reviews from Maps | url, days_limit (default: 3) |
google_shopping |
Shopping product data | url |
google_play_store |
App store data | url |
Other Platforms (9 datasets)
| Type | Description | Required Inputs |
|---|---|---|
apple_app_store |
iOS app data | url |
x_posts |
X (Twitter) post data | url |
reddit_posts |
Reddit post data | url |
github_repository_file |
GitHub file content | url |
yahoo_finance_business |
Financial business data | url |
reuter_news |
News article data | url |
zillow_properties_listing |
Real estate listing data | url |
booking_hotel_listings |
Hotel listing data | url |
Bright Data uses "zones" to manage API configurations. Only BrightDataSERP needs one. It uses a zone named serp, and you do not have to create it: if the account does not have the zone yet, the first search creates it. This needs an API key with the Admin or Ops role, and that first search can take a few minutes while the new zone starts up.
To use another zone, set it when creating the tool:
from langchain_brightdata import BrightDataSERP
serp = BrightDataSERP(
bright_data_api_key="your-api-key",
zone="my_serp_zone"
)The zone cannot be set in a search call, so an AI model can never choose the zone. A call that sets a zone is not sent: it returns an error that says to set the zone on the tool.
You can see your zones in the Bright Data dashboard.
MIT License - see LICENSE for details.