Skip to content

Commit 6f43545

Browse files
authored
Merge pull request #12 from ScrapeGraphAI/pre/beta
Pre/beta
2 parents 4740c58 + 636db26 commit 6f43545

16 files changed

+517
-140
lines changed

β€Žscrapegraph-py/CHANGELOG.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
## [1.6.0-beta.1](https://github.com/ScrapeGraphAI/scrapegraph-sdk/compare/v1.5.0...v1.6.0-beta.1) (2024-12-05)
2+
3+
4+
### Features
5+
6+
* changed SyncClient to Client ([9e1e496](https://github.com/ScrapeGraphAI/scrapegraph-sdk/commit/9e1e496059cd24810a96b818da1811830586f94b))
7+
8+
9+
### Bug Fixes
10+
11+
* logger working properly now ([9712d4c](https://github.com/ScrapeGraphAI/scrapegraph-sdk/commit/9712d4c39eea860f813e86a5e2ffc14db6d3a655))
12+
* updated env variable loading ([2643f11](https://github.com/ScrapeGraphAI/scrapegraph-sdk/commit/2643f11c968f0daab26529d513f08c2817763b50))
13+
14+
15+
### CI
16+
17+
* **release:** 1.4.3-beta.2 [skip ci] ([8ab6147](https://github.com/ScrapeGraphAI/scrapegraph-sdk/commit/8ab61476b6763b936e2e7d423b04bb51983fb8ea))
18+
* **release:** 1.4.3-beta.3 [skip ci] ([1bc26c7](https://github.com/ScrapeGraphAI/scrapegraph-sdk/commit/1bc26c738443f7f52492a7b2cbe7c9f335315797))
19+
* **release:** 1.5.0-beta.1 [skip ci] ([8900f7b](https://github.com/ScrapeGraphAI/scrapegraph-sdk/commit/8900f7bf53239b6a73fb41196f5327d05763bae4))
20+
21+
## [1.5.0-beta.1](https://github.com/ScrapeGraphAI/scrapegraph-sdk/compare/v1.4.3-beta.3...v1.5.0-beta.1) (2024-12-05)
22+
23+
24+
### Features
25+
26+
* changed SyncClient to Client ([9e1e496](https://github.com/ScrapeGraphAI/scrapegraph-sdk/commit/9e1e496059cd24810a96b818da1811830586f94b))
27+
28+
129
## [1.5.0](https://github.com/ScrapeGraphAI/scrapegraph-sdk/compare/v1.4.3...v1.5.0) (2024-12-04)
230

331

@@ -7,6 +35,19 @@
735

836
## [1.4.3](https://github.com/ScrapeGraphAI/scrapegraph-sdk/compare/v1.4.2...v1.4.3) (2024-12-03)
937

38+
## [1.4.3-beta.3](https://github.com/ScrapeGraphAI/scrapegraph-sdk/compare/v1.4.3-beta.2...v1.4.3-beta.3) (2024-12-05)
39+
40+
41+
### Bug Fixes
42+
43+
* updated env variable loading ([2643f11](https://github.com/ScrapeGraphAI/scrapegraph-sdk/commit/2643f11c968f0daab26529d513f08c2817763b50))
44+
45+
## [1.4.3-beta.2](https://github.com/ScrapeGraphAI/scrapegraph-sdk/compare/v1.4.3-beta.1...v1.4.3-beta.2) (2024-12-05)
46+
47+
48+
### Bug Fixes
49+
50+
* logger working properly now ([9712d4c](https://github.com/ScrapeGraphAI/scrapegraph-sdk/commit/9712d4c39eea860f813e86a5e2ffc14db6d3a655))
1051

1152
### Bug Fixes
1253

β€Žscrapegraph-py/examples/async_smartscraper_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import asyncio
22

33
from scrapegraph_py import AsyncClient
4-
from scrapegraph_py.logger import get_logger
4+
from scrapegraph_py.logger import sgai_logger
55

6-
get_logger(level="DEBUG")
6+
sgai_logger.set_logging(level="INFO")
77

88

99
async def main():

β€Žscrapegraph-py/examples/smartscraper_schema_async_example.py renamed to β€Žscrapegraph-py/examples/async_smartscraper_schema_example.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import asyncio
2+
23
from pydantic import BaseModel, Field
4+
35
from scrapegraph_py import AsyncClient
46

57

@@ -27,5 +29,6 @@ async def main():
2729

2830
await sgai_client.close()
2931

32+
3033
if __name__ == "__main__":
3134
asyncio.run(main())
Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
from scrapegraph_py import SyncClient
2-
from scrapegraph_py.logger import get_logger
3-
4-
get_logger(level="DEBUG")
5-
6-
# Initialize the client
7-
sgai_client = SyncClient(api_key="your-api-key-here")
8-
9-
# Example request_id (replace with an actual request_id from a previous request)
10-
request_id = "your-request-id-here"
11-
12-
# Submit feedback for a previous request
13-
feedback_response = sgai_client.submit_feedback(
14-
request_id=request_id,
15-
rating=5, # Rating from 1-5
16-
feedback_text="The extraction was accurate and exactly what I needed!",
17-
)
18-
print(f"\nFeedback Response: {feedback_response}")
19-
20-
# Get previous results using get_smartscraper
21-
previous_result = sgai_client.get_smartscraper(request_id=request_id)
22-
print(f"\nRetrieved Previous Result: {previous_result}")
23-
24-
sgai_client.close()
1+
from scrapegraph_py import Client
2+
from scrapegraph_py.logger import sgai_logger
3+
4+
sgai_logger.set_logging(level="INFO")
5+
6+
# Initialize the client
7+
sgai_client = Client(api_key="your-api-key-here")
8+
9+
# Example request_id (replace with an actual request_id from a previous request)
10+
request_id = "your-request-id-here"
11+
12+
# Check remaining credits
13+
credits = sgai_client.get_credits()
14+
print(f"Credits Info: {credits}")
15+
16+
# Submit feedback for a previous request
17+
feedback_response = sgai_client.submit_feedback(
18+
request_id=request_id,
19+
rating=5, # Rating from 1-5
20+
feedback_text="The extraction was accurate and exactly what I needed!",
21+
)
22+
print(f"\nFeedback Response: {feedback_response}")
23+
24+
# Get previous results using get_smartscraper
25+
previous_result = sgai_client.get_smartscraper(request_id=request_id)
26+
print(f"\nRetrieved Previous Result: {previous_result}")
27+
28+
sgai_client.close()

β€Žscrapegraph-py/examples/get_credits_example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from scrapegraph_py import SyncClient
2-
from scrapegraph_py.logger import get_logger
1+
from scrapegraph_py import Client
2+
from scrapegraph_py.logger import sgai_logger
33

4-
get_logger(level="DEBUG")
4+
sgai_logger.set_level("DEBUG")
55

66
# Initialize the client
7-
sgai_client = SyncClient(api_key="your-api-key-here")
7+
sgai_client = Client(api_key="your-api-key-here")
88

99
# Check remaining credits
1010
credits = sgai_client.get_credits()

β€Žscrapegraph-py/examples/smartscraper_example.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from scrapegraph_py import SyncClient
2-
from scrapegraph_py.logger import get_logger
1+
from scrapegraph_py import Client
2+
from scrapegraph_py.logger import sgai_logger
33

4-
get_logger(level="DEBUG")
4+
sgai_logger.set_logging(level="INFO")
55

6-
# Initialize the client
7-
sgai_client = SyncClient(api_key="your-api-key-here")
6+
# Initialize the client with explicit API key
7+
sgai_client = Client(api_key="your-api-key-here")
88

99
# SmartScraper request
1010
response = sgai_client.smartscraper(

β€Žscrapegraph-py/examples/smartscraper_schema_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from pydantic import BaseModel, Field
22

3-
from scrapegraph_py import SyncClient
3+
from scrapegraph_py import Client
44

55

66
# Define a Pydantic model for the output schema
@@ -11,7 +11,7 @@ class WebpageSchema(BaseModel):
1111

1212

1313
# Initialize the client
14-
sgai_client = SyncClient(api_key="your-api-key-here")
14+
sgai_client = Client(api_key="your-api-key-here")
1515

1616
# SmartScraper request with output schema
1717
response = sgai_client.smartscraper(
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from .async_client import AsyncClient
2-
from .client import SyncClient
2+
from .client import Client
33

4-
__all__ = ["SyncClient", "AsyncClient"]
4+
__all__ = ["Client", "AsyncClient"]

β€Žscrapegraph-py/scrapegraph_py/async_client.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def from_env(
4949

5050
def __init__(
5151
self,
52-
api_key: str,
52+
api_key: str = None,
5353
verify_ssl: bool = True,
5454
timeout: float = 120,
5555
max_retries: int = 3,
@@ -58,13 +58,24 @@ def __init__(
5858
"""Initialize AsyncClient with configurable parameters.
5959
6060
Args:
61-
api_key: API key for authentication
61+
api_key: API key for authentication. If None, will try to load from environment
6262
verify_ssl: Whether to verify SSL certificates
6363
timeout: Request timeout in seconds
6464
max_retries: Maximum number of retry attempts
6565
retry_delay: Delay between retries in seconds
6666
"""
6767
logger.info("πŸ”‘ Initializing AsyncClient")
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+
6879
validate_api_key(api_key)
6980
logger.debug(
7081
f"πŸ› οΈ Configuration: verify_ssl={verify_ssl}, timeout={timeout}, max_retries={max_retries}"

β€Žscrapegraph-py/scrapegraph_py/client.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Sync client implementation goes here
1+
# Client implementation goes here
22
from typing import Any, Optional
33

44
import requests
@@ -17,7 +17,7 @@
1717
from 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

Comments
Β (0)