Call the scrapegraph-py extract endpoint across SDK versions.
(
api_key: Optional[str],
url: str,
prompt: str,
schema: Optional[Type[BaseModel]] = None,
)
| 53 | |
| 54 | |
| 55 | def extract( |
| 56 | api_key: Optional[str], |
| 57 | url: str, |
| 58 | prompt: str, |
| 59 | schema: Optional[Type[BaseModel]] = None, |
| 60 | ) -> dict: |
| 61 | """Call the scrapegraph-py extract endpoint across SDK versions.""" |
| 62 | api = _detect_api() |
| 63 | |
| 64 | if api == "v3": |
| 65 | from scrapegraph_py import ExtractRequest, ScrapeGraphAI |
| 66 | |
| 67 | kwargs: dict[str, Any] = {"url": url, "prompt": prompt} |
| 68 | schema_dict = _schema_to_dict(schema) |
| 69 | if schema_dict is not None: |
| 70 | kwargs["schema_"] = schema_dict |
| 71 | with ScrapeGraphAI(api_key=api_key) as client: |
| 72 | return _unwrap_result(client.extract(ExtractRequest(**kwargs))) |
| 73 | |
| 74 | from scrapegraph_py import Client |
| 75 | |
| 76 | with Client(api_key=api_key) as client: |
| 77 | return client.extract(url=url, prompt=prompt, output_schema=schema) |
| 78 | |
| 79 | |
| 80 | def scrape(api_key: Optional[str], url: str) -> dict: |
nothing calls this directly
no test coverage detected