1- # Sync client implementation goes here
1+ # Client implementation goes here
22from typing import Any , Optional
33
44import requests
1717from scrapegraph_py .utils .helpers import handle_sync_response , validate_api_key
1818
1919
20- class SyncClient :
20+ class Client :
2121 @classmethod
2222 def from_env (
2323 cls ,
@@ -26,7 +26,7 @@ def from_env(
2626 max_retries : int = 3 ,
2727 retry_delay : float = 1.0 ,
2828 ):
29- """Initialize SyncClient using API key from environment variable.
29+ """Initialize Client using API key from environment variable.
3030
3131 Args:
3232 verify_ssl: Whether to verify SSL certificates
@@ -35,6 +35,7 @@ def from_env(
3535 retry_delay: Delay between retries in seconds
3636 """
3737 from os import getenv
38+
3839 api_key = getenv ("SGAI_API_KEY" )
3940 if not api_key :
4041 raise ValueError ("SGAI_API_KEY environment variable not set" )
@@ -48,22 +49,33 @@ def from_env(
4849
4950 def __init__ (
5051 self ,
51- api_key : str ,
52+ api_key : str = None ,
5253 verify_ssl : bool = True ,
5354 timeout : float = 120 ,
5455 max_retries : int = 3 ,
5556 retry_delay : float = 1.0 ,
5657 ):
57- """Initialize SyncClient with configurable parameters.
58+ """Initialize Client with configurable parameters.
5859
5960 Args:
60- api_key: API key for authentication
61+ api_key: API key for authentication. If None, will try to load from environment
6162 verify_ssl: Whether to verify SSL certificates
6263 timeout: Request timeout in seconds
6364 max_retries: Maximum number of retry attempts
6465 retry_delay: Delay between retries in seconds
6566 """
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+
6779 validate_api_key (api_key )
6880 logger .debug (
6981 f"π οΈ Configuration: verify_ssl={ verify_ssl } , timeout={ timeout } , max_retries={ max_retries } "
@@ -95,7 +107,7 @@ def __init__(
95107 if not verify_ssl :
96108 urllib3 .disable_warnings (urllib3 .exceptions .InsecureRequestWarning )
97109
98- logger .info ("β
SyncClient initialized successfully" )
110+ logger .info ("β
Client initialized successfully" )
99111
100112 def _make_request (self , method : str , url : str , ** kwargs ) -> Any :
101113 """Make HTTP request with error handling."""
@@ -199,7 +211,7 @@ def submit_feedback(
199211
200212 def close (self ):
201213 """Close the session to free up resources"""
202- logger .info ("π Closing SyncClient session" )
214+ logger .info ("π Closing Client session" )
203215 self .session .close ()
204216 logger .debug ("β
Session closed successfully" )
205217
0 commit comments