MCPcopy Create free account
hub / github.com/ScrapeGraphAI/Scrapegraph-ai / extract

Function extract

scrapegraphai/integrations/scrapegraph_py_compat.py:55–77  ·  view source on GitHub ↗

Call the scrapegraph-py extract endpoint across SDK versions.

(
    api_key: Optional[str],
    url: str,
    prompt: str,
    schema: Optional[Type[BaseModel]] = None,
)

Source from the content-addressed store, hash-verified

53
54
55def 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
80def scrape(api_key: Optional[str], url: str) -> dict:

Callers

nothing calls this directly

Calls 3

_detect_apiFunction · 0.85
_schema_to_dictFunction · 0.85
_unwrap_resultFunction · 0.85

Tested by

no test coverage detected