Skip to content

Commit acf93c0

Browse files
committed
2 parents 2791691 + 96f1c0b commit acf93c0

File tree

3 files changed

+66
-32
lines changed

3 files changed

+66
-32
lines changed

scrapegraph-py/CHANGELOG.md

+29
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
## [1.4.3](https://github.com/ScrapeGraphAI/scrapegraph-sdk/compare/v1.4.2...v1.4.3) (2024-12-03)
2+
3+
4+
### Bug Fixes
5+
6+
* updated comment ([8250818](https://github.com/ScrapeGraphAI/scrapegraph-sdk/commit/825081883940bc1caa37f4f13e10f710770aeb9c))
7+
8+
9+
### chore
10+
11+
* improved url validation ([83eac53](https://github.com/ScrapeGraphAI/scrapegraph-sdk/commit/83eac530269a767e5469c4aded1656fe00a2cdc0))
12+
13+
14+
### CI
15+
16+
* **release:** 1.4.3-beta.1 [skip ci] ([cd1169b](https://github.com/ScrapeGraphAI/scrapegraph-sdk/commit/cd1169b584ffa621d99961e2e95db96a28037e13))
17+
18+
## [1.4.3-beta.1](https://github.com/ScrapeGraphAI/scrapegraph-sdk/compare/v1.4.2...v1.4.3-beta.1) (2024-12-03)
19+
20+
21+
### Bug Fixes
22+
23+
* updated comment ([8250818](https://github.com/ScrapeGraphAI/scrapegraph-sdk/commit/825081883940bc1caa37f4f13e10f710770aeb9c))
24+
25+
26+
### chore
27+
28+
* improved url validation ([83eac53](https://github.com/ScrapeGraphAI/scrapegraph-sdk/commit/83eac530269a767e5469c4aded1656fe00a2cdc0))
29+
130
## [1.4.2](https://github.com/ScrapeGraphAI/scrapegraph-sdk/compare/v1.4.1...v1.4.2) (2024-12-02)
231

332

scrapegraph-py/scrapegraph_py/async_client.py

+29-28
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,35 @@
1818

1919

2020
class AsyncClient:
21+
@classmethod
22+
def from_env(
23+
cls,
24+
verify_ssl: bool = True,
25+
timeout: float = 120,
26+
max_retries: int = 3,
27+
retry_delay: float = 1.0,
28+
):
29+
"""Initialize AsyncClient using API key from environment variable.
30+
31+
Args:
32+
verify_ssl: Whether to verify SSL certificates
33+
timeout: Request timeout in seconds
34+
max_retries: Maximum number of retry attempts
35+
retry_delay: Delay between retries in seconds
36+
"""
37+
from os import getenv
38+
39+
api_key = getenv("SGAI_API_KEY")
40+
if not api_key:
41+
raise ValueError("SGAI_API_KEY environment variable not set")
42+
return cls(
43+
api_key=api_key,
44+
verify_ssl=verify_ssl,
45+
timeout=timeout,
46+
max_retries=max_retries,
47+
retry_delay=retry_delay,
48+
)
49+
2150
def __init__(
2251
self,
2352
api_key: str,
@@ -54,34 +83,6 @@ def __init__(
5483

5584
logger.info("✅ AsyncClient initialized successfully")
5685

57-
@classmethod
58-
def from_env(
59-
cls,
60-
verify_ssl: bool = True,
61-
timeout: float = 120,
62-
max_retries: int = 3,
63-
retry_delay: float = 1.0,
64-
):
65-
"""Initialize AsyncClient using API key from environment variable.
66-
67-
Args:
68-
verify_ssl: Whether to verify SSL certificates
69-
timeout: Request timeout in seconds
70-
max_retries: Maximum number of retry attempts
71-
retry_delay: Delay between retries in seconds
72-
"""
73-
from os import getenv
74-
api_key = getenv("SGAI_API_KEY")
75-
if not api_key:
76-
raise ValueError("SGAI_API_KEY environment variable not set")
77-
return cls(
78-
api_key=api_key,
79-
verify_ssl=verify_ssl,
80-
timeout=timeout,
81-
max_retries=max_retries,
82-
retry_delay=retry_delay,
83-
)
84-
8586
async def _make_request(self, method: str, url: str, **kwargs) -> Any:
8687
"""Make HTTP request with retry logic."""
8788
for attempt in range(self.max_retries):

scrapegraph-py/scrapegraph_py/models/smartscraper.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from typing import Optional, Type
44
from uuid import UUID
55

6-
import validators
76
from pydantic import BaseModel, Field, model_validator
87

98

@@ -25,9 +24,13 @@ def validate_user_prompt(self) -> "SmartScraperRequest":
2524

2625
@model_validator(mode="after")
2726
def validate_url(self) -> "SmartScraperRequest":
28-
url = self.website_url
29-
if not validators.url(url):
30-
raise ValueError(f"Invalid URL: {url}")
27+
if self.website_url is None or not self.website_url.strip():
28+
raise ValueError("Website URL cannot be empty")
29+
if not (
30+
self.website_url.startswith("http://")
31+
or self.website_url.startswith("https://")
32+
):
33+
raise ValueError("Invalid URL")
3134
return self
3235

3336
def model_dump(self, *args, **kwargs) -> dict:
@@ -46,6 +49,7 @@ class GetSmartScraperRequest(BaseModel):
4649
@model_validator(mode="after")
4750
def validate_request_id(self) -> "GetSmartScraperRequest":
4851
try:
52+
# Validate the request_id is a valid UUID
4953
UUID(self.request_id)
5054
except ValueError:
5155
raise ValueError("request_id must be a valid UUID")

0 commit comments

Comments
 (0)