|
6 | 6 | [](https://github.com/psf/black)
|
7 | 7 | [](https://scrapegraph-py.readthedocs.io/en/latest/?badge=latest)
|
8 | 8 |
|
9 |
| -Official Python SDK for the ScrapeGraph AI API - Smart web scraping powered by AI. |
10 |
| - |
11 |
| -## 🚀 Features |
12 |
| - |
13 |
| -- ✨ Smart web scraping with AI |
14 |
| -- 🔄 Both sync and async clients |
15 |
| -- 📊 Structured output with Pydantic schemas |
16 |
| -- 🔍 Detailed logging with emojis |
17 |
| -- ⚡ Automatic retries and error handling |
18 |
| -- 🔐 Secure API authentication |
| 9 | +Official Python SDK for the ScrapeGraph API - Smart web scraping powered by AI. |
19 | 10 |
|
20 | 11 | ## 📦 Installation
|
21 | 12 |
|
22 |
| -### Using pip |
23 |
| - |
24 |
| -``` |
| 13 | +```bash |
25 | 14 | pip install scrapegraph-py
|
26 | 15 | ```
|
27 | 16 |
|
28 |
| -### Using uv |
| 17 | +## 🚀 Features |
29 | 18 |
|
30 |
| -We recommend using [uv](https://docs.astral.sh/uv/) to install the dependencies and pre-commit hooks. |
| 19 | +- 🤖 AI-powered web scraping |
| 20 | +- 🔄 Both sync and async clients |
| 21 | +- 📊 Structured output with Pydantic schemas |
| 22 | +- 🔍 Detailed logging |
| 23 | +- ⚡ Automatic retries |
| 24 | +- 🔐 Secure authentication |
31 | 25 |
|
32 |
| -``` |
33 |
| -# Install uv if you haven't already |
34 |
| -pip install uv |
| 26 | +## 🎯 Quick Start |
35 | 27 |
|
36 |
| -# Install dependencies |
37 |
| -uv sync |
| 28 | +```python |
| 29 | +from scrapegraph_py import Client |
38 | 30 |
|
39 |
| -# Install pre-commit hooks |
40 |
| -uv run pre-commit install |
| 31 | +client = Client(api_key="your-api-key-here") |
41 | 32 | ```
|
42 | 33 |
|
43 |
| -## 🔧 Quick Start |
44 |
| - |
45 | 34 | > [!NOTE]
|
46 |
| -> If you prefer, you can use the environment variables to configure the API key and load them using `load_dotenv()` |
| 35 | +> You can set the `SGAI_API_KEY` environment variable and initialize the client without parameters: `client = Client()` |
47 | 36 |
|
48 |
| -```python |
49 |
| -from scrapegraph_py import SyncClient |
50 |
| -from scrapegraph_py.logger import get_logger |
| 37 | +## 📚 Available Endpoints |
| 38 | + |
| 39 | +### 🔍 SmartScraper |
51 | 40 |
|
52 |
| -# Enable debug logging |
53 |
| -logger = get_logger(level="DEBUG") |
| 41 | +Scrapes any webpage using AI to extract specific information. |
| 42 | + |
| 43 | +```python |
| 44 | +from scrapegraph_py import Client |
54 | 45 |
|
55 |
| -# Initialize client |
56 |
| -sgai_client = SyncClient(api_key="your-api-key-here") |
| 46 | +client = Client(api_key="your-api-key-here") |
57 | 47 |
|
58 |
| -# Make a request |
59 |
| -response = sgai_client.smartscraper( |
| 48 | +# Basic usage |
| 49 | +response = client.smartscraper( |
60 | 50 | website_url="https://example.com",
|
61 | 51 | user_prompt="Extract the main heading and description"
|
62 | 52 | )
|
63 | 53 |
|
64 |
| -print(response["result"]) |
65 |
| -``` |
66 |
| - |
67 |
| -## 🎯 Examples |
68 |
| - |
69 |
| -### Async Usage |
70 |
| - |
71 |
| -```python |
72 |
| -import asyncio |
73 |
| -from scrapegraph_py import AsyncClient |
74 |
| - |
75 |
| -async def main(): |
76 |
| - async with AsyncClient(api_key="your-api-key-here") as sgai_client: |
77 |
| - response = await sgai_client.smartscraper( |
78 |
| - website_url="https://example.com", |
79 |
| - user_prompt="Summarize the main content" |
80 |
| - ) |
81 |
| - print(response["result"]) |
82 |
| - |
83 |
| -asyncio.run(main()) |
| 54 | +print(response) |
84 | 55 | ```
|
85 | 56 |
|
86 | 57 | <details>
|
87 |
| -<summary><b>With Output Schema</b></summary> |
| 58 | +<summary>Output Schema (Optional)</summary> |
88 | 59 |
|
89 | 60 | ```python
|
90 | 61 | from pydantic import BaseModel, Field
|
91 |
| -from scrapegraph_py import SyncClient |
| 62 | +from scrapegraph_py import Client |
| 63 | + |
| 64 | +client = Client(api_key="your-api-key-here") |
92 | 65 |
|
93 | 66 | class WebsiteData(BaseModel):
|
94 | 67 | title: str = Field(description="The page title")
|
95 | 68 | description: str = Field(description="The meta description")
|
96 | 69 |
|
97 |
| -sgai_client = SyncClient(api_key="your-api-key-here") |
98 |
| -response = sgai_client.smartscraper( |
| 70 | +response = client.smartscraper( |
99 | 71 | website_url="https://example.com",
|
100 | 72 | user_prompt="Extract the title and description",
|
101 | 73 | output_schema=WebsiteData
|
102 | 74 | )
|
103 |
| - |
104 |
| -print(response["result"]) |
105 | 75 | ```
|
| 76 | + |
106 | 77 | </details>
|
107 | 78 |
|
108 |
| -## 📚 Documentation |
| 79 | +### 📝 Markdownify |
109 | 80 |
|
110 |
| -For detailed documentation, visit [docs.scrapegraphai.com](https://docs.scrapegraphai.com) |
| 81 | +Converts any webpage into clean, formatted markdown. |
111 | 82 |
|
112 |
| -## 🛠️ Development |
| 83 | +```python |
| 84 | +from scrapegraph_py import Client |
113 | 85 |
|
114 |
| -### Setup |
| 86 | +client = Client(api_key="your-api-key-here") |
115 | 87 |
|
116 |
| -1. Clone the repository: |
117 |
| -``` |
118 |
| -git clone https://github.com/ScrapeGraphAI/scrapegraph-sdk.git |
119 |
| -cd scrapegraph-sdk/scrapegraph-py |
120 |
| -``` |
| 88 | +response = client.markdownify( |
| 89 | + website_url="https://example.com" |
| 90 | +) |
121 | 91 |
|
122 |
| -2. Install dependencies: |
123 |
| -``` |
124 |
| -uv sync |
| 92 | +print(response) |
125 | 93 | ```
|
126 | 94 |
|
127 |
| -3. Install pre-commit hooks: |
128 |
| -``` |
129 |
| -uv run pre-commit install |
130 |
| -``` |
| 95 | +### 💻 LocalScraper |
131 | 96 |
|
132 |
| -### Running Tests |
| 97 | +Extracts information from HTML content using AI. |
133 | 98 |
|
134 |
| -``` |
135 |
| -# Run all tests |
136 |
| -uv run pytest |
| 99 | +```python |
| 100 | +from scrapegraph_py import Client |
| 101 | + |
| 102 | +client = Client(api_key="your-api-key-here") |
| 103 | + |
| 104 | +html_content = """ |
| 105 | +<html> |
| 106 | + <body> |
| 107 | + <h1>Company Name</h1> |
| 108 | + <p>We are a technology company focused on AI solutions.</p> |
| 109 | + <div class="contact"> |
| 110 | + |
| 111 | + </div> |
| 112 | + </body> |
| 113 | +</html> |
| 114 | +""" |
| 115 | + |
| 116 | +response = client.localscraper( |
| 117 | + user_prompt="Extract the company description", |
| 118 | + website_html=html_content |
| 119 | +) |
137 | 120 |
|
138 |
| -# Run specific test file |
139 |
| -poetry run pytest tests/test_client.py |
| 121 | +print(response) |
140 | 122 | ```
|
141 | 123 |
|
142 |
| -## 📝 License |
| 124 | +## ⚡ Async Support |
143 | 125 |
|
144 |
| -This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
| 126 | +All endpoints support async operations: |
| 127 | + |
| 128 | +```python |
| 129 | +import asyncio |
| 130 | +from scrapegraph_py import AsyncClient |
145 | 131 |
|
146 |
| -## 🤝 Contributing |
| 132 | +async def main(): |
| 133 | + async with AsyncClient() as client: |
| 134 | + response = await client.smartscraper( |
| 135 | + website_url="https://example.com", |
| 136 | + user_prompt="Extract the main content" |
| 137 | + ) |
| 138 | + print(response) |
| 139 | + |
| 140 | +asyncio.run(main()) |
| 141 | +``` |
147 | 142 |
|
148 |
| -Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change. |
| 143 | +## 📖 Documentation |
149 | 144 |
|
150 |
| -1. Fork the repository |
151 |
| -2. Create your feature branch (`git checkout -b feature/AmazingFeature`) |
152 |
| -3. Commit your changes (`git commit -m 'Add some AmazingFeature'`) |
153 |
| -4. Push to the branch (`git push origin feature/AmazingFeature`) |
154 |
| -5. Open a Pull Request |
| 145 | +For detailed documentation, visit [scrapegraphai.com/docs](https://scrapegraphai.com/docs) |
155 | 146 |
|
156 |
| -## 🔗 Links |
| 147 | +## 🛠️ Development |
157 | 148 |
|
158 |
| -- [Website](https://scrapegraphai.com) |
159 |
| -- [Documentation](https://scrapegraphai.com/documentation) |
160 |
| -- [GitHub](https://github.com/ScrapeGraphAI/scrapegraph-sdk) |
| 149 | +For information about setting up the development environment and contributing to the project, see our [Contributing Guide](CONTRIBUTING.md). |
161 | 150 |
|
162 |
| -## 💬 Support |
| 151 | +## 💬 Support & Feedback |
163 | 152 |
|
164 | 153 |
|
165 | 154 | - 💻 GitHub Issues: [Create an issue](https://github.com/ScrapeGraphAI/scrapegraph-sdk/issues)
|
166 | 155 | - 🌟 Feature Requests: [Request a feature](https://github.com/ScrapeGraphAI/scrapegraph-sdk/issues/new)
|
| 156 | +- ⭐ API Feedback: You can also submit feedback programmatically using the feedback endpoint: |
| 157 | + ```python |
| 158 | + from scrapegraph_py import Client |
| 159 | + |
| 160 | + client = Client(api_key="your-api-key-here") |
| 161 | + |
| 162 | + client.submit_feedback( |
| 163 | + request_id="your-request-id", |
| 164 | + rating=5, |
| 165 | + feedback_text="Great results!" |
| 166 | + ) |
| 167 | + ``` |
| 168 | + |
| 169 | +## 📄 License |
| 170 | + |
| 171 | +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
| 172 | + |
| 173 | +## 🔗 Links |
| 174 | + |
| 175 | +- [Website](https://scrapegraphai.com) |
| 176 | +- [Documentation](https://scrapegraphai.com/docs) |
| 177 | +- [GitHub](https://github.com/ScrapeGraphAI/scrapegraph-sdk) |
167 | 178 |
|
168 | 179 | ---
|
169 | 180 |
|
|
0 commit comments