Skip to content

Commit 282e842

Browse files
עידן וילנסקיעידן וילנסקי
authored andcommitted
2 parents 975569f + d9717f9 commit 282e842

File tree

1 file changed

+102
-110
lines changed

1 file changed

+102
-110
lines changed

README.md

Lines changed: 102 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11

22
<img width="1300" height="200" alt="sdk-banner(1)" src="https://github.com/user-attachments/assets/c4a7857e-10dd-420b-947a-ed2ea5825cb8" />
33

4-
<h3 align="center">A Python SDK for the Bright Data's Data extraction and Web unlocking tools, providing easy-to-use scalable methods for web scraping, web searches and more.</h3>
5-
6-
7-
For a quick start you can try to run our example files in this repositories under the "Codespace" section.
4+
```python
5+
pip install brightdata-sdk
6+
```
7+
<h3 align="center">Python SDK by Bright Data, providing easy-to-use scalable methods for web search & scraping</h3>
8+
<p></p>
89

910
## Features
1011

@@ -18,58 +19,37 @@ For a quick start you can try to run our example files in this repositories unde
1819

1920
## Installation
2021
To install the package, open your terminal:
21-
> [!NOTE]
22-
> If you are using macOS you will need to open a virtual environment for your project first.
2322

24-
```bash
23+
```python
2524
pip install brightdata-sdk
2625
```
26+
> If using macOS, first open a virtual environment for your project
2727
2828
## Quick Start
2929

30+
Create a [Bright Data](https://brightdata.com/) account and copy your API key
31+
3032
### 1. Initialize the Client
31-
> [!IMPORTANT]
32-
> Go to your [**account settings**](https://brightdata.com/cp/setting/users), to verify that your API key have **"admin permissions"**.
3333

3434
```python
3535
from brightdata import bdclient
3636

3737
client = bdclient(api_token="your_api_token_here") # can also be defined as BRIGHTDATA_API_TOKEN in your .env file
3838
```
3939

40-
Or you can use a custom zone name
40+
Or you can configure a custom zone name
41+
4142
```python
4243
client = bdclient(
4344
api_token="your_token",
4445
auto_create_zones=False, # Else it creates the Zone automatically
45-
web_unlocker_zone="custom_zone", # Custom zone name for web scraping
46-
serp_zone="custom_serp_zone" # Custom zone name for search requests
46+
web_unlocker_zone="custom_zone",
47+
serp_zone="custom_serp_zone"
4748
)
48-
```
49-
> [!TIP]
50-
> Hover over the "bdclient" (or over each function in the package) with your cursor to see all its available parameters.
51-
5249

53-
### 2. Scrape Websites
54-
55-
```python
56-
# Single URL
57-
result = client.scrape("https://example.com")
58-
59-
# Multiple URLs (parallel processing)
60-
urls = ["https://example1.com", "https://example2.com", "https://example3.com"]
61-
results = client.scrape(urls)
62-
63-
# Custom options
64-
result = client.scrape(
65-
"https://example.com",
66-
format="raw",
67-
country="gb",
68-
data_format="screenshot"
69-
)
7050
```
7151

72-
### 3. Search Engine Results
52+
### 2. Search Engine Results
7353

7454
```python
7555
# Single search query
@@ -90,51 +70,56 @@ results = client.search(
9070
)
9171
```
9272

93-
### 4. Download Content
73+
> [!TIP]
74+
> Hover over the "search" or each function in the package, to see all its available parameters.
9475
95-
```python
96-
# Download scraped content
97-
data = client.scrape("https://example.com")
98-
client.download_content(data, "results.json", "json") # Auto-generate filename if not specified
99-
```
76+
![Hover-Over1](https://github.com/user-attachments/assets/51324485-5769-48d5-8f13-0b534385142e)
10077

101-
## Configuration
78+
### 3. Scrape Websites
10279

103-
### Environment Variables
80+
```python
81+
# Single URL
82+
result = client.scrape("https://example.com")
10483

105-
Create a `.env` file in your project root:
84+
# Multiple URLs (parallel processing)
85+
urls = ["https://example1.com", "https://example2.com", "https://example3.com"]
86+
results = client.scrape(urls)
10687

107-
```env
108-
BRIGHTDATA_API_TOKEN=your_bright_data_api_token
109-
WEB_UNLOCKER_ZONE=your_web_unlocker_zone # Optional
110-
SERP_ZONE=your_serp_zone # Optional
88+
# Custom options
89+
result = client.scrape(
90+
"https://example.com",
91+
format="raw",
92+
country="gb",
93+
data_format="screenshot"
94+
)
11195
```
11296

113-
### Manage Zones
97+
### 4. Download Content
11498

11599
```python
116-
# List all active zones
117-
zones = client.list_zones()
118-
print(f"Found {len(zones)} zones")
100+
# Download scraped content
101+
data = client.scrape("https://example.com")
102+
client.download_content(data)
119103
```
120104

121-
## API Reference
122-
123-
### bdclient Class
105+
## Function Parameters
106+
<details>
107+
<summary>🔍 <strong>Search(...)</strong></summary>
108+
109+
Searches using the SERP API. Accepts the same arguments as scrape(), plus:
124110

125111
```python
126-
bdclient(
127-
api_token: str = None,
128-
auto_create_zones: bool = True,
129-
web_unlocker_zone: str = None,
130-
serp_zone: str = None,
131-
)
112+
- `query`: Search query string or list of queries
113+
- `search_engine`: "google", "bing", or "yandex"
114+
- Other parameters same as scrape()
132115
```
116+
117+
</details>
118+
<details>
119+
<summary>🔗 <strong>scrape(...)</strong></summary>
133120

134-
### Key Methods
135-
136-
#### scrape(...)
137121
Scrapes a single URL or list of URLs using the Web Unlocker.
122+
138123
```python
139124
- `url`: Single URL string or list of URLs
140125
- `zone`: Zone identifier (auto-configured if None)
@@ -147,48 +132,23 @@ Scrapes a single URL or list of URLs using the Web Unlocker.
147132
- `timeout`: Request timeout in seconds (default: 30)
148133
```
149134

150-
#### search(...)
151-
Searches using the SERP API. Accepts the same arguments as scrape(), plus:
152-
```python
153-
- `query`: Search query string or list of queries
154-
- `search_engine`: "google", "bing", or "yandex"
155-
- Other parameters same as scrape()
156-
```
157-
158-
#### download_content(...)
135+
</details>
136+
<details>
137+
<summary>💾 <strong>Download_Content(...)</strong></summary>
159138

160139
Save content to local file.
140+
161141
```python
162142
- `content`: Content to save
163143
- `filename`: Output filename (auto-generated if None)
164144
- `format`: File format ("json", "csv", "txt", etc.)
165145
```
166146

167-
#### list_zones()
168-
169-
List all active zones in your Bright Data account.
147+
</details>
148+
<details>
149+
<summary>⚙️ <strong>Configuration Constants</strong></summary>
170150

171-
## Error Handling
172-
173-
The SDK includes built-in input validation and retry logic:
174-
```python
175-
try:
176-
result = client.scrape("https://example.com")
177-
except ValueError as e:
178-
print(f"Invalid input: {e}")
179-
except Exception as e:
180-
print(f"API error: {e}")
181-
```
182-
183-
## Production Features
184-
185-
- **Retry Logic**: Automatic retries with exponential backoff for network failures
186-
- **Input Validation**: Validates URLs, zone names, and parameters
187-
- **Connection Pooling**: Efficient HTTP connection management
188-
- **Logging**: Comprehensive logging for debugging and monitoring
189-
- **Zone Auto-Creation**: Automatically creates required zones if they don't exist
190-
191-
## Configuration Constants
151+
<p></p>
192152

193153
| Constant | Default | Description |
194154
| ---------------------- | ------- | ------------------------------- |
@@ -198,27 +158,59 @@ except Exception as e:
198158
| `MAX_RETRIES` | `3` | Retry attempts on failure |
199159
| `RETRY_BACKOFF_FACTOR` | `1.5` | Exponential backoff multiplier |
200160

201-
## Getting Your API Token
202-
203-
1. Sign up at [brightdata.com](https://brightdata.com/), and navigate to your dashboard
204-
2. Create or access your API credentials
205-
3. Copy your API token and paste it in your .env or code file
161+
</details>
206162

207-
## Development
163+
## Advanced Configuration
208164

209-
For development installation, open your terminal:
165+
<details>
166+
<summary>🔧 <strong>Environment Variables</strong></summary>
210167

211-
```bash
212-
git clone https://github.com/brightdata/bright-data-sdk-python.git
168+
Create a `.env` file in your project root:
213169

214-
# If you are using Mac you will need to open a virtual environment for your project first.
215-
cd bright-data-sdk-python
216-
pip install .
170+
```env
171+
BRIGHTDATA_API_TOKEN=your_bright_data_api_token
172+
WEB_UNLOCKER_ZONE=your_web_unlocker_zone # Optional
173+
SERP_ZONE=your_serp_zone # Optional
217174
```
218175

219-
## License
176+
</details>
177+
<details>
178+
<summary>🌐 <strong>Manage Zones</strong></summary>
179+
180+
List all active zones
181+
182+
```python
183+
# List all active zones
184+
zones = client.list_zones()
185+
print(f"Found {len(zones)} zones")
186+
```
220187

221-
This project is licensed under the MIT License.
188+
</details>
189+
<details>
190+
<summary>👥 <strong>Client Management</strong></summary>
191+
192+
bdclient Class
193+
194+
```python
195+
bdclient(
196+
api_token: str = None,
197+
auto_create_zones: bool = True,
198+
web_unlocker_zone: str = None,
199+
serp_zone: str = None,
200+
)
201+
```
202+
203+
</details>
204+
<details>
205+
<summary>⚠️ <strong>Error Handling</strong></summary>
206+
207+
bdclient Class
208+
209+
The SDK includes built-in input validation and retry logic
210+
211+
In case of zone related problems, use the **list_zones()** function to check your active zones, and check that your [**account settings**](https://brightdata.com/cp/setting/users), to verify that your API key have **"admin permissions"**.
212+
213+
</details>
222214

223215
## Support
224216

0 commit comments

Comments
 (0)