Skip to content

Pre/beta #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions scrapegraph-py/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
## [1.6.0-beta.1](https://github.com/ScrapeGraphAI/scrapegraph-sdk/compare/v1.5.0...v1.6.0-beta.1) (2024-12-05)


### Features

* changed SyncClient to Client ([9e1e496](https://github.com/ScrapeGraphAI/scrapegraph-sdk/commit/9e1e496059cd24810a96b818da1811830586f94b))


### Bug Fixes

* logger working properly now ([9712d4c](https://github.com/ScrapeGraphAI/scrapegraph-sdk/commit/9712d4c39eea860f813e86a5e2ffc14db6d3a655))
* updated env variable loading ([2643f11](https://github.com/ScrapeGraphAI/scrapegraph-sdk/commit/2643f11c968f0daab26529d513f08c2817763b50))


### CI

* **release:** 1.4.3-beta.2 [skip ci] ([8ab6147](https://github.com/ScrapeGraphAI/scrapegraph-sdk/commit/8ab61476b6763b936e2e7d423b04bb51983fb8ea))
* **release:** 1.4.3-beta.3 [skip ci] ([1bc26c7](https://github.com/ScrapeGraphAI/scrapegraph-sdk/commit/1bc26c738443f7f52492a7b2cbe7c9f335315797))
* **release:** 1.5.0-beta.1 [skip ci] ([8900f7b](https://github.com/ScrapeGraphAI/scrapegraph-sdk/commit/8900f7bf53239b6a73fb41196f5327d05763bae4))

## [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)


### Features

* changed SyncClient to Client ([9e1e496](https://github.com/ScrapeGraphAI/scrapegraph-sdk/commit/9e1e496059cd24810a96b818da1811830586f94b))


## [1.5.0](https://github.com/ScrapeGraphAI/scrapegraph-sdk/compare/v1.4.3...v1.5.0) (2024-12-04)


Expand All @@ -7,6 +35,19 @@

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

## [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)


### Bug Fixes

* updated env variable loading ([2643f11](https://github.com/ScrapeGraphAI/scrapegraph-sdk/commit/2643f11c968f0daab26529d513f08c2817763b50))

## [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)


### Bug Fixes

* logger working properly now ([9712d4c](https://github.com/ScrapeGraphAI/scrapegraph-sdk/commit/9712d4c39eea860f813e86a5e2ffc14db6d3a655))

### Bug Fixes

Expand Down
4 changes: 2 additions & 2 deletions scrapegraph-py/examples/async_smartscraper_example.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import asyncio

from scrapegraph_py import AsyncClient
from scrapegraph_py.logger import get_logger
from scrapegraph_py.logger import sgai_logger

get_logger(level="DEBUG")
sgai_logger.set_logging(level="INFO")


async def main():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio

from pydantic import BaseModel, Field

from scrapegraph_py import AsyncClient


Expand Down Expand Up @@ -27,5 +29,6 @@ async def main():

await sgai_client.close()


if __name__ == "__main__":
asyncio.run(main())
52 changes: 28 additions & 24 deletions scrapegraph-py/examples/feedback_example.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
from scrapegraph_py import SyncClient
from scrapegraph_py.logger import get_logger

get_logger(level="DEBUG")

# Initialize the client
sgai_client = SyncClient(api_key="your-api-key-here")

# Example request_id (replace with an actual request_id from a previous request)
request_id = "your-request-id-here"

# Submit feedback for a previous request
feedback_response = sgai_client.submit_feedback(
request_id=request_id,
rating=5, # Rating from 1-5
feedback_text="The extraction was accurate and exactly what I needed!",
)
print(f"\nFeedback Response: {feedback_response}")

# Get previous results using get_smartscraper
previous_result = sgai_client.get_smartscraper(request_id=request_id)
print(f"\nRetrieved Previous Result: {previous_result}")

sgai_client.close()
from scrapegraph_py import Client
from scrapegraph_py.logger import sgai_logger

sgai_logger.set_logging(level="INFO")

# Initialize the client
sgai_client = Client(api_key="your-api-key-here")

# Example request_id (replace with an actual request_id from a previous request)
request_id = "your-request-id-here"

# Check remaining credits
credits = sgai_client.get_credits()
print(f"Credits Info: {credits}")

# Submit feedback for a previous request
feedback_response = sgai_client.submit_feedback(
request_id=request_id,
rating=5, # Rating from 1-5
feedback_text="The extraction was accurate and exactly what I needed!",
)
print(f"\nFeedback Response: {feedback_response}")

# Get previous results using get_smartscraper
previous_result = sgai_client.get_smartscraper(request_id=request_id)
print(f"\nRetrieved Previous Result: {previous_result}")

sgai_client.close()
8 changes: 4 additions & 4 deletions scrapegraph-py/examples/get_credits_example.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from scrapegraph_py import SyncClient
from scrapegraph_py.logger import get_logger
from scrapegraph_py import Client
from scrapegraph_py.logger import sgai_logger

get_logger(level="DEBUG")
sgai_logger.set_level("DEBUG")

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

# Check remaining credits
credits = sgai_client.get_credits()
Expand Down
10 changes: 5 additions & 5 deletions scrapegraph-py/examples/smartscraper_example.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from scrapegraph_py import SyncClient
from scrapegraph_py.logger import get_logger
from scrapegraph_py import Client
from scrapegraph_py.logger import sgai_logger

get_logger(level="DEBUG")
sgai_logger.set_logging(level="INFO")

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

# SmartScraper request
response = sgai_client.smartscraper(
Expand Down
4 changes: 2 additions & 2 deletions scrapegraph-py/examples/smartscraper_schema_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pydantic import BaseModel, Field

from scrapegraph_py import SyncClient
from scrapegraph_py import Client


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


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

# SmartScraper request with output schema
response = sgai_client.smartscraper(
Expand Down
4 changes: 2 additions & 2 deletions scrapegraph-py/scrapegraph_py/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .async_client import AsyncClient
from .client import SyncClient
from .client import Client

__all__ = ["SyncClient", "AsyncClient"]
__all__ = ["Client", "AsyncClient"]
15 changes: 13 additions & 2 deletions scrapegraph-py/scrapegraph_py/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def from_env(

def __init__(
self,
api_key: str,
api_key: str = None,
verify_ssl: bool = True,
timeout: float = 120,
max_retries: int = 3,
Expand All @@ -58,13 +58,24 @@ def __init__(
"""Initialize AsyncClient with configurable parameters.

Args:
api_key: API key for authentication
api_key: API key for authentication. If None, will try to load from environment
verify_ssl: Whether to verify SSL certificates
timeout: Request timeout in seconds
max_retries: Maximum number of retry attempts
retry_delay: Delay between retries in seconds
"""
logger.info("πŸ”‘ Initializing AsyncClient")

# Try to get API key from environment if not provided
if api_key is None:
from os import getenv

api_key = getenv("SGAI_API_KEY")
if not api_key:
raise ValueError(
"SGAI_API_KEY not provided and not found in environment"
)

validate_api_key(api_key)
logger.debug(
f"πŸ› οΈ Configuration: verify_ssl={verify_ssl}, timeout={timeout}, max_retries={max_retries}"
Expand Down
30 changes: 21 additions & 9 deletions scrapegraph-py/scrapegraph_py/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sync client implementation goes here
# Client implementation goes here
from typing import Any, Optional

import requests
Expand All @@ -17,7 +17,7 @@
from scrapegraph_py.utils.helpers import handle_sync_response, validate_api_key


class SyncClient:
class Client:
@classmethod
def from_env(
cls,
Expand All @@ -26,7 +26,7 @@ def from_env(
max_retries: int = 3,
retry_delay: float = 1.0,
):
"""Initialize SyncClient using API key from environment variable.
"""Initialize Client using API key from environment variable.

Args:
verify_ssl: Whether to verify SSL certificates
Expand All @@ -35,6 +35,7 @@ def from_env(
retry_delay: Delay between retries in seconds
"""
from os import getenv

api_key = getenv("SGAI_API_KEY")
if not api_key:
raise ValueError("SGAI_API_KEY environment variable not set")
Expand All @@ -48,22 +49,33 @@ def from_env(

def __init__(
self,
api_key: str,
api_key: str = None,
verify_ssl: bool = True,
timeout: float = 120,
max_retries: int = 3,
retry_delay: float = 1.0,
):
"""Initialize SyncClient with configurable parameters.
"""Initialize Client with configurable parameters.

Args:
api_key: API key for authentication
api_key: API key for authentication. If None, will try to load from environment
verify_ssl: Whether to verify SSL certificates
timeout: Request timeout in seconds
max_retries: Maximum number of retry attempts
retry_delay: Delay between retries in seconds
"""
logger.info("πŸ”‘ Initializing SyncClient")
logger.info("πŸ”‘ Initializing Client")

# Try to get API key from environment if not provided
if api_key is None:
from os import getenv

api_key = getenv("SGAI_API_KEY")
if not api_key:
raise ValueError(
"SGAI_API_KEY not provided and not found in environment"
)

validate_api_key(api_key)
logger.debug(
f"πŸ› οΈ Configuration: verify_ssl={verify_ssl}, timeout={timeout}, max_retries={max_retries}"
Expand Down Expand Up @@ -95,7 +107,7 @@ def __init__(
if not verify_ssl:
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

logger.info("βœ… SyncClient initialized successfully")
logger.info("βœ… Client initialized successfully")

def _make_request(self, method: str, url: str, **kwargs) -> Any:
"""Make HTTP request with error handling."""
Expand Down Expand Up @@ -199,7 +211,7 @@ def submit_feedback(

def close(self):
"""Close the session to free up resources"""
logger.info("πŸ”’ Closing SyncClient session")
logger.info("πŸ”’ Closing Client session")
self.session.close()
logger.debug("βœ… Session closed successfully")

Expand Down
Loading