@@ -11,27 +11,29 @@ description: 'Install and get started with ScrapeGraphAI v2 SDKs'
1111
1212## Python SDK
1313
14+ Requires ** Python ≥ 3.12** .
15+
1416``` bash
15- pip install scrapegraph-py
17+ pip install " scrapegraph-py>=2.1.0 "
1618```
1719
1820** Usage:**
1921
2022``` python
21- from scrapegraph_py import Client
23+ from scrapegraph_py import ScrapeGraphAI
2224
23- client = Client (api_key = " your-api-key-here" )
25+ sgai = ScrapeGraphAI (api_key = " your-api-key-here" )
2426
2527# Extract data from a website
26- response = client.extract(
28+ res = sgai.extract(
29+ " Extract information about the company" ,
2730 url = " https://scrapegraphai.com" ,
28- prompt = " Extract information about the company"
2931)
30- print (response )
32+ print (res.data.json_data if res.status == " success " else res.error )
3133```
3234
3335<Note >
34- You can also set the ` SGAI_API_KEY ` environment variable and initialize the client without parameters: ` client = Client ()`
36+ You can also set the ` SGAI_API_KEY ` environment variable and initialize the client without parameters: ` sgai = ScrapeGraphAI ()` .
3537</Note >
3638
3739For more advanced usage, see the [ Python SDK documentation] ( /sdks/python ) .
@@ -110,22 +112,25 @@ Both SDKs support structured output using schemas:
110112### Python Example
111113
112114``` python
113- from scrapegraph_py import Client
114- from pydantic import BaseModel, Field
115+ from scrapegraph_py import ScrapeGraphAI
115116
116- class CompanyInfo (BaseModel ):
117- company_name: str = Field(description = " The company name" )
118- description: str = Field(description = " Company description" )
119- website: str = Field(description = " Company website URL" )
120- industry: str = Field(description = " Industry sector" )
117+ sgai = ScrapeGraphAI(api_key = " your-api-key" )
121118
122- client = Client( api_key = " your-api-key " )
123- response = client.extract(
119+ res = sgai.extract(
120+ " Extract company information " ,
124121 url = " https://scrapegraphai.com" ,
125- prompt = " Extract company information" ,
126- output_schema = CompanyInfo
122+ schema = {
123+ " type" : " object" ,
124+ " properties" : {
125+ " company_name" : {" type" : " string" , " description" : " The company name" },
126+ " description" : {" type" : " string" , " description" : " Company description" },
127+ " website" : {" type" : " string" , " description" : " Company website URL" },
128+ " industry" : {" type" : " string" , " description" : " Industry sector" },
129+ },
130+ " required" : [" company_name" ],
131+ },
127132)
128- print (response )
133+ print (res.data.json_data if res.status == " success " else res.error )
129134```
130135
131136### JavaScript Example
0 commit comments