Skip to content

Commit bd91bf2

Browse files
committed
style: Fix code formatting (Black) and linting (Ruff)
1 parent 5b8aea3 commit bd91bf2

28 files changed

+142
-310
lines changed

src/brightdata/api/async_unblocker.py

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async def trigger(
7070
zone: str,
7171
url: str,
7272
customer: Optional[str] = None,
73-
**kwargs # Additional params like country, format, etc.
73+
**kwargs, # Additional params like country, format, etc.
7474
) -> Optional[str]:
7575
"""
7676
Trigger async unblocker request.
@@ -105,21 +105,14 @@ async def trigger(
105105
payload.update(kwargs)
106106

107107
async with self.engine.post_to_url(
108-
f"{self.engine.BASE_URL}{self.TRIGGER_ENDPOINT}",
109-
params=params,
110-
json_data=payload
108+
f"{self.engine.BASE_URL}{self.TRIGGER_ENDPOINT}", params=params, json_data=payload
111109
) as response:
112110
# Extract response_id from x-response-id header
113111
# Note: This is different from datasets API which returns snapshot_id in body
114112
response_id = response.headers.get("x-response-id")
115113
return response_id
116114

117-
async def get_status(
118-
self,
119-
zone: str,
120-
response_id: str,
121-
customer: Optional[str] = None
122-
) -> str:
115+
async def get_status(self, zone: str, response_id: str, customer: Optional[str] = None) -> str:
123116
"""
124117
Check if response is ready.
125118
@@ -142,18 +135,14 @@ async def get_status(
142135
>>> if status == "ready":
143136
... # Fetch results
144137
"""
145-
params = {
146-
"zone": zone,
147-
"response_id": response_id
148-
}
138+
params = {"zone": zone, "response_id": response_id}
149139

150140
# Add customer to query params if provided
151141
if customer:
152142
params["customer"] = customer
153143

154144
async with self.engine.get_from_url(
155-
f"{self.engine.BASE_URL}{self.FETCH_ENDPOINT}",
156-
params=params
145+
f"{self.engine.BASE_URL}{self.FETCH_ENDPOINT}", params=params
157146
) as response:
158147
if response.status == 200:
159148
return "ready"
@@ -168,7 +157,7 @@ async def fetch_result(
168157
zone: str,
169158
response_id: str,
170159
response_format: str = "json",
171-
customer: Optional[str] = None
160+
customer: Optional[str] = None,
172161
) -> Any:
173162
"""
174163
Fetch results when ready.
@@ -203,18 +192,14 @@ async def fetch_result(
203192
... customer="hl_67e5ed38"
204193
... )
205194
"""
206-
params = {
207-
"zone": zone,
208-
"response_id": response_id
209-
}
195+
params = {"zone": zone, "response_id": response_id}
210196

211197
# Add customer to query params if provided
212198
if customer:
213199
params["customer"] = customer
214200

215201
async with self.engine.get_from_url(
216-
f"{self.engine.BASE_URL}{self.FETCH_ENDPOINT}",
217-
params=params
202+
f"{self.engine.BASE_URL}{self.FETCH_ENDPOINT}", params=params
218203
) as response:
219204
if response.status == 200:
220205
# Success - parse based on format

src/brightdata/api/scrape_service.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
All methods are async-only. For sync usage, use SyncBrightDataClient.
66
"""
77

8-
from typing import Union, List, TYPE_CHECKING
8+
from typing import TYPE_CHECKING
99

10-
from ..models import ScrapeResult
1110

1211
if TYPE_CHECKING:
1312
from ..client import BrightDataClient
@@ -182,5 +181,3 @@ def instagram(self):
182181
bearer_token=self._client.token, engine=self._client.engine
183182
)
184183
return self._instagram
185-
186-

src/brightdata/api/search_service.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ async def google(
103103
**kwargs,
104104
)
105105

106-
107106
async def bing(
108107
self,
109108
query: Union[str, List[str]],
@@ -132,7 +131,6 @@ async def bing(
132131
**kwargs,
133132
)
134133

135-
136134
async def yandex(
137135
self,
138136
query: Union[str, List[str]],
@@ -161,7 +159,6 @@ async def yandex(
161159
**kwargs,
162160
)
163161

164-
165162
@property
166163
def amazon(self):
167164
"""

src/brightdata/api/serp/base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ async def search(
153153
**kwargs,
154154
)
155155

156-
157156
async def _search_single_async(
158157
self,
159158
query: str,

src/brightdata/api/web_unlocker.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ async def _scrape_single_async_unblocker(
308308
url=url,
309309
format=response_format,
310310
method=method,
311-
country=country.upper() if country else None
311+
country=country.upper() if country else None,
312312
)
313313
except Exception as e:
314314
return ScrapeResult(
@@ -370,9 +370,7 @@ async def _scrape_single_async_unblocker(
370370

371371
try:
372372
data = await self.async_unblocker.fetch_result(
373-
zone,
374-
response_id,
375-
response_format=response_format
373+
zone, response_id, response_format=response_format
376374
)
377375

378376
root_domain = extract_root_domain(url)

src/brightdata/cli/commands/scrape.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ def scrape_url(ctx: click.Context, url: str, country: str, response_format: str)
5050
"""Scrape any URL using Web Unlocker."""
5151
try:
5252
client = create_client(ctx.obj["api_key"])
53-
result = client.scrape_url(
54-
url=url, country=country, response_format=response_format
55-
)
53+
result = client.scrape_url(url=url, country=country, response_format=response_format)
5654
output_result(result, ctx.obj["output_format"], ctx.obj["output_file"])
5755
except Exception as e:
5856
handle_error(e)

src/brightdata/client.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@ async def scrape_url(
507507
poll_timeout=poll_timeout,
508508
)
509509

510-
511510
async def __aenter__(self):
512511
"""Async context manager entry."""
513512
await self.engine.__aenter__()
@@ -517,9 +516,7 @@ async def __aenter__(self):
517516
is_valid = await self.test_connection()
518517
if not is_valid:
519518
await self.engine.__aexit__(None, None, None)
520-
raise AuthenticationError(
521-
"Token validation failed. Please check your API token."
522-
)
519+
raise AuthenticationError("Token validation failed. Please check your API token.")
523520

524521
await self._ensure_zones()
525522
return self
@@ -533,5 +530,3 @@ def __repr__(self) -> str:
533530
token_preview = f"{self.token[:10]}...{self.token[-5:]}" if self.token else "None"
534531
status = "Connected" if self._is_connected else "Not tested"
535532
return f"<BrightDataClient token={token_preview} status='{status}'>"
536-
537-

src/brightdata/core/engine.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
warnings.filterwarnings("ignore", category=ResourceWarning, message="unclosed.*<ssl.SSLSocket")
2525
# Suppress RuntimeWarning for coroutines not awaited in __del__ cleanup
2626
# This happens because aiohttp's connector.close() is async in 3.x
27-
warnings.filterwarnings("ignore", category=RuntimeWarning, message="coroutine.*TCPConnector.close.*never awaited")
27+
warnings.filterwarnings(
28+
"ignore", category=RuntimeWarning, message="coroutine.*TCPConnector.close.*never awaited"
29+
)
2830

2931

3032
class AsyncEngine:

src/brightdata/scrapers/amazon/scraper.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ async def products(
9090

9191
return await self._scrape_urls(url=url, dataset_id=self.DATASET_ID, timeout=timeout)
9292

93-
9493
def products_sync(
9594
self,
9695
url: Union[str, List[str]],
@@ -101,9 +100,11 @@ def products_sync(
101100
102101
See products() for full documentation.
103102
"""
103+
104104
async def _run():
105105
async with self.engine:
106106
return await self.products(url, timeout)
107+
107108
return asyncio.run(_run())
108109

109110
# ============================================================================
@@ -139,7 +140,6 @@ async def products_trigger(
139140
urls=url, sdk_function=sdk_function or "products_trigger"
140141
)
141142

142-
143143
def products_trigger_sync(self, url: Union[str, List[str]]) -> ScrapeJob:
144144
"""Trigger Amazon products scrape (sync version)."""
145145
return asyncio.run(self.products_trigger(url))
@@ -159,7 +159,6 @@ async def products_status(self, snapshot_id: str) -> str:
159159
"""
160160
return await self._check_status_async(snapshot_id)
161161

162-
163162
def products_status_sync(self, snapshot_id: str) -> str:
164163
"""Check Amazon products scrape status (sync version)."""
165164
return asyncio.run(self.products_status(snapshot_id))
@@ -179,7 +178,6 @@ async def products_fetch(self, snapshot_id: str) -> Any:
179178
"""
180179
return await self._fetch_results_async(snapshot_id)
181180

182-
183181
def products_fetch_sync(self, snapshot_id: str) -> Any:
184182
"""Fetch Amazon products scrape results (sync version)."""
185183
return asyncio.run(self.products_fetch(snapshot_id))
@@ -276,7 +274,6 @@ async def reviews(
276274
return results
277275
return result
278276

279-
280277
def reviews_sync(
281278
self,
282279
url: Union[str, List[str]],
@@ -290,9 +287,11 @@ def reviews_sync(
290287
291288
See reviews() for full documentation.
292289
"""
290+
293291
async def _run():
294292
async with self.engine:
295293
return await self.reviews(url, pastDays, keyWord, numOfReviews, timeout)
294+
296295
return asyncio.run(_run())
297296

298297
# ============================================================================
@@ -332,7 +331,6 @@ async def reviews_trigger(
332331
sdk_function=sdk_function or "reviews_trigger",
333332
)
334333

335-
336334
def reviews_trigger_sync(
337335
self,
338336
url: Union[str, List[str]],
@@ -347,7 +345,6 @@ async def reviews_status(self, snapshot_id: str) -> str:
347345
"""Check Amazon reviews scrape status."""
348346
return await self._check_status_async(snapshot_id)
349347

350-
351348
def reviews_status_sync(self, snapshot_id: str) -> str:
352349
"""Check Amazon reviews scrape status (sync version)."""
353350
return asyncio.run(self.reviews_status(snapshot_id))
@@ -356,7 +353,6 @@ async def reviews_fetch(self, snapshot_id: str) -> Any:
356353
"""Fetch Amazon reviews scrape results."""
357354
return await self._fetch_results_async(snapshot_id)
358355

359-
360356
def reviews_fetch_sync(self, snapshot_id: str) -> Any:
361357
"""Fetch Amazon reviews scrape results (sync version)."""
362358
return asyncio.run(self.reviews_fetch(snapshot_id))
@@ -397,7 +393,6 @@ async def sellers(
397393

398394
return await self._scrape_urls(url=url, dataset_id=self.DATASET_ID_SELLERS, timeout=timeout)
399395

400-
401396
def sellers_sync(
402397
self,
403398
url: Union[str, List[str]],
@@ -408,9 +403,11 @@ def sellers_sync(
408403
409404
See sellers() for full documentation.
410405
"""
406+
411407
async def _run():
412408
async with self.engine:
413409
return await self.sellers(url, timeout)
410+
414411
return asyncio.run(_run())
415412

416413
# ============================================================================
@@ -444,7 +441,6 @@ async def sellers_trigger(
444441
sdk_function=sdk_function or "sellers_trigger",
445442
)
446443

447-
448444
def sellers_trigger_sync(self, url: Union[str, List[str]]) -> ScrapeJob:
449445
"""Trigger Amazon sellers scrape (sync version)."""
450446
return asyncio.run(self.sellers_trigger(url))
@@ -453,7 +449,6 @@ async def sellers_status(self, snapshot_id: str) -> str:
453449
"""Check Amazon sellers scrape status."""
454450
return await self._check_status_async(snapshot_id)
455451

456-
457452
def sellers_status_sync(self, snapshot_id: str) -> str:
458453
"""Check Amazon sellers scrape status (sync version)."""
459454
return asyncio.run(self.sellers_status(snapshot_id))
@@ -462,7 +457,6 @@ async def sellers_fetch(self, snapshot_id: str) -> Any:
462457
"""Fetch Amazon sellers scrape results."""
463458
return await self._fetch_results_async(snapshot_id)
464459

465-
466460
def sellers_fetch_sync(self, snapshot_id: str) -> Any:
467461
"""Fetch Amazon sellers scrape results (sync version)."""
468462
return asyncio.run(self.sellers_fetch(snapshot_id))

src/brightdata/scrapers/amazon/search.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ async def products(
164164
timeout=timeout,
165165
)
166166

167-
168167
def products_sync(
169168
self,
170169
keyword: Optional[Union[str, List[str]]] = None,
@@ -182,6 +181,7 @@ def products_sync(
182181
183182
See products() for full documentation.
184183
"""
184+
185185
async def _run():
186186
async with self.engine:
187187
return await self.products(
@@ -195,6 +195,7 @@ async def _run():
195195
country=country,
196196
timeout=timeout,
197197
)
198+
198199
return asyncio.run(_run())
199200

200201
# ============================================================================

0 commit comments

Comments
 (0)