1
- # Sync client implementation goes here
1
+ # Client implementation goes here
2
2
from typing import Any , Optional
3
3
4
4
import requests
17
17
from scrapegraph_py .utils .helpers import handle_sync_response , validate_api_key
18
18
19
19
20
- class SyncClient :
20
+ class Client :
21
21
@classmethod
22
22
def from_env (
23
23
cls ,
@@ -26,7 +26,7 @@ def from_env(
26
26
max_retries : int = 3 ,
27
27
retry_delay : float = 1.0 ,
28
28
):
29
- """Initialize SyncClient using API key from environment variable.
29
+ """Initialize Client using API key from environment variable.
30
30
31
31
Args:
32
32
verify_ssl: Whether to verify SSL certificates
@@ -35,6 +35,7 @@ def from_env(
35
35
retry_delay: Delay between retries in seconds
36
36
"""
37
37
from os import getenv
38
+
38
39
api_key = getenv ("SGAI_API_KEY" )
39
40
if not api_key :
40
41
raise ValueError ("SGAI_API_KEY environment variable not set" )
@@ -48,22 +49,33 @@ def from_env(
48
49
49
50
def __init__ (
50
51
self ,
51
- api_key : str ,
52
+ api_key : str = None ,
52
53
verify_ssl : bool = True ,
53
54
timeout : float = 120 ,
54
55
max_retries : int = 3 ,
55
56
retry_delay : float = 1.0 ,
56
57
):
57
- """Initialize SyncClient with configurable parameters.
58
+ """Initialize Client with configurable parameters.
58
59
59
60
Args:
60
- api_key: API key for authentication
61
+ api_key: API key for authentication. If None, will try to load from environment
61
62
verify_ssl: Whether to verify SSL certificates
62
63
timeout: Request timeout in seconds
63
64
max_retries: Maximum number of retry attempts
64
65
retry_delay: Delay between retries in seconds
65
66
"""
66
- logger .info ("π Initializing SyncClient" )
67
+ logger .info ("π Initializing Client" )
68
+
69
+ # Try to get API key from environment if not provided
70
+ if api_key is None :
71
+ from os import getenv
72
+
73
+ api_key = getenv ("SGAI_API_KEY" )
74
+ if not api_key :
75
+ raise ValueError (
76
+ "SGAI_API_KEY not provided and not found in environment"
77
+ )
78
+
67
79
validate_api_key (api_key )
68
80
logger .debug (
69
81
f"π οΈ Configuration: verify_ssl={ verify_ssl } , timeout={ timeout } , max_retries={ max_retries } "
@@ -95,7 +107,7 @@ def __init__(
95
107
if not verify_ssl :
96
108
urllib3 .disable_warnings (urllib3 .exceptions .InsecureRequestWarning )
97
109
98
- logger .info ("β
SyncClient initialized successfully" )
110
+ logger .info ("β
Client initialized successfully" )
99
111
100
112
def _make_request (self , method : str , url : str , ** kwargs ) -> Any :
101
113
"""Make HTTP request with error handling."""
@@ -199,7 +211,7 @@ def submit_feedback(
199
211
200
212
def close (self ):
201
213
"""Close the session to free up resources"""
202
- logger .info ("π Closing SyncClient session" )
214
+ logger .info ("π Closing Client session" )
203
215
self .session .close ()
204
216
logger .debug ("β
Session closed successfully" )
205
217
0 commit comments