> ## Documentation Index
> Fetch the complete documentation index at: https://docs.langchain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Brightdataunlocker integration

> Integrate with the Brightdataunlocker tool using LangChain Python.

[Bright Data](https://brightdata.com/) provides a powerful Web Unlocker API that allows you to access websites that might be protected by anti-bot measures, geo-restrictions, or other access limitations, making it particularly useful for AI agents requiring reliable web content extraction.

## Overview

### Integration details

| Class                                                                  | Package                                                                  | Serializable | JS support |                                               Version                                              |
| :--------------------------------------------------------------------- | :----------------------------------------------------------------------- | :----------: | :--------: | :------------------------------------------------------------------------------------------------: |
| [`BrightDataUnlocker`](https://pypi.org/project/langchain-brightdata/) | [`langchain-brightdata`](https://pypi.org/project/langchain-brightdata/) |       ✅      |      ❌     | ![PyPI - Version](https://img.shields.io/pypi/v/langchain-brightdata?style=flat-square\&label=%20) |

### Tool features

| Native async | Returns artifact | Return data                                |            Pricing           |
| :----------: | :--------------: | :----------------------------------------- | :--------------------------: |
|       ❌      |         ❌        | HTML, Markdown, or screenshot of web pages | Requires Bright Data account |

## Setup

The integration lives in the `langchain-brightdata` package.

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install langchain-brightdata
```

You'll need a Bright Data API key to use this tool. You can set it as an environment variable:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import os

os.environ["BRIGHT_DATA_API_KEY"] = "your-api-key"
```

Or pass it directly when initializing the tool:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_brightdata import BrightDataUnlocker

unlocker_tool = BrightDataUnlocker(bright_data_api_key="your-api-key")
```

## Instantiation

Here we show how to instantiate an instance of the BrightDataUnlocker tool. This tool allows you to access websites that may be protected by anti-bot measures, geo-restrictions, or other access limitations using Bright Data's Web Unlocker service.

The tool accepts various parameters during instantiation:

* `bright_data_api_key` (required, str): Your Bright Data API key for authentication.
* `format` (optional, Literal\["raw"]): Format of the response content. Default is "raw".
* `country` (optional, str): Two-letter country code for geo-specific access (e.g., "us", "gb", "de", "jp"). Set this when you need to view the website as if accessing from a specific country. Default is None.
* `zone` (optional, str): Bright Data zone to use for the request. The "unlocker" zone is optimized for accessing websites that might block regular requests. Default is "unlocker".
* `data_format` (optional, Literal\["html", "markdown", "screenshot"]): Output format for the retrieved content. Options include:
  * "html" - Returns the standard HTML content (default)
  * "markdown" - Returns content converted to markdown format
  * "screenshot" - Returns a PNG screenshot of the rendered page

## Invocation

### Basic usage

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_brightdata import BrightDataUnlocker

# Initialize the tool
unlocker_tool = BrightDataUnlocker(
    bright_data_api_key="your-api-key"  # Optional if set in environment variables
)

# Access a webpage
result = unlocker_tool.invoke("https://example.com")

print(result)
```

### Advanced usage with parameters

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_brightdata import BrightDataUnlocker

unlocker_tool = BrightDataUnlocker(
    bright_data_api_key="your-api-key",
)

# Access a webpage with specific parameters
result = unlocker_tool.invoke(
    {
        "url": "https://example.com/region-restricted-content",
        "country": "gb",  # Access as if from Great Britain
        "data_format": "html",  # Get content in markdown format
        "zone": "unlocker",  # Use the unlocker zone
    }
)

print(result)
```

## Customization options

The BrightDataUnlocker tool accepts several parameters for customization:

| Parameter     | Type | Description                                                        |
| :------------ | :--- | :----------------------------------------------------------------- |
| `url`         | str  | The URL to access                                                  |
| `format`      | str  | Format of the response content (default: "raw")                    |
| `country`     | str  | Two-letter country code for geo-specific access (e.g., "us", "gb") |
| `zone`        | str  | Bright Data zone to use (default: "unlocker")                      |
| `data_format` | str  | Output format: None (HTML), "markdown", or "screenshot"            |

## Data format options

The `data_format` parameter allows you to specify how the content should be returned:

* `None` or `"html"` (default): Returns the standard HTML content of the page
* `"markdown"`: Returns the content converted to markdown format, which is useful for feeding directly to LLMs
* `"screenshot"`: Returns a PNG screenshot of the rendered page, useful for visual analysis

## Use within an agent

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_brightdata import BrightDataUnlocker
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain.agents import create_agent


# Initialize the LLM
llm = ChatGoogleGenerativeAI(model="gemini-2.5-flash", google_api_key="your-api-key")

# Initialize the tool
bright_data_tool = BrightDataUnlocker(bright_data_api_key="your-api-key")

# Create the agent
agent = create_agent(llm, [bright_data_tool])

# Input URLs or prompt
user_input = "Get the content from https://example.com/region-restricted-page - access it from GB"

# Stream the agent's output step by step
stream = agent.stream_events({"messages": user_input}, version="v3")
for snapshot in stream.values:
    snapshot["messages"][-1].pretty_print()
```

***

## API reference

* [Bright Data API Documentation](https://docs.brightdata.com/scraping-automation/web-unlocker/introduction)

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/tools/brightdata_unlocker.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
