Skip to main content

🌐 ScrapeGraph Python SDK

PyPI version Python Support License Code style: black Documentation Status

Official Python SDK for the ScrapeGraph AI API - Smart web scraping powered by AI.

🚀 Features

  • ✨ Smart web scraping with AI
  • 🔄 Both sync and async clients
  • 📊 Structured output with Pydantic schemas
  • 🔍 Detailed logging with emojis
  • ⚡ Automatic retries and error handling
  • 🔐 Secure API authentication

📦 Installation

Using pip

pip install scrapegraph-py

Using uv

We recommend using uv to install the dependencies and pre-commit hooks.

# Install uv if you haven't already
pip install uv

# Install dependencies
uv sync

# Install pre-commit hooks
uv run pre-commit install

🔧 Quick Start

[!NOTE] If you prefer, you can use the environment variables to configure the API key and load them using load_dotenv()

from scrapegraph_py import SyncClient
from scrapegraph_py.logger import get_logger

# Enable debug logging
logger = get_logger(level="DEBUG")

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

# Make a request
response = sgai_client.smartscraper(
    website_url="https://example.com",
    user_prompt="Extract the main heading and description"
)

print(response["result"])

🎯 Examples

Async Usage

import asyncio
from scrapegraph_py import AsyncClient

async def main():
    async with AsyncClient(api_key="your-api-key-here") as sgai_client:
        response = await sgai_client.smartscraper(
            website_url="https://example.com",
            user_prompt="Summarize the main content"
        )
        print(response["result"])

asyncio.run(main())
With Output Schema
from pydantic import BaseModel, Field
from scrapegraph_py import SyncClient

class WebsiteData(BaseModel):
    title: str = Field(description="The page title")
    description: str = Field(description="The meta description")

sgai_client = SyncClient(api_key="your-api-key-here")
response = sgai_client.smartscraper(
    website_url="https://example.com",
    user_prompt="Extract the title and description",
    output_schema=WebsiteData
)

print(response["result"])

📚 Documentation

For detailed documentation, visit docs.scrapegraphai.com

🛠️ Development

Setup

  1. Clone the repository:
git clone https://github.com/ScrapeGraphAI/scrapegraph-sdk.git
cd scrapegraph-sdk/scrapegraph-py
  1. Install dependencies:
uv sync
  1. Install pre-commit hooks:
uv run pre-commit install

Running Tests

# Run all tests
uv run pytest

# Run specific test file
poetry run pytest tests/test_client.py

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🤝 Contributing

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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

🔗 Links

💬 Support


Made with ❤️ by ScrapeGraph AI

Metadata

Release files for scrapegraph-py 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scrapegraph-py 1.3.0
File Size Uploaded
scrapegraph_py-1.3.0.tar.gz 104.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for scrapegraph-py 1.3.0
File Interpreter ABI Platform
scrapegraph_py-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 116.6 kB

Release files / scrapegraph_py-1.3.0.tar.gz

Download URL scrapegraph_py-1.3.0.tar.gz
Size 104.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4c09e1bb0a806f79874ced808582140a7578e7f8b044a8b493bb45026be8d554
BLAKE2b-256 checksum
How to use checksums
e819ecc2bb2bf698c5115ce1d85ab42806adafd2a95ab735f7b9f22f7f20e734
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.12

Release files / scrapegraph_py-1.3.0-py3-none-any.whl

Download URL scrapegraph_py-1.3.0-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
924a1c34797da6ad7b133c29763630b0d959976a03fb57d08b69f23e8985694d
BLAKE2b-256 checksum
How to use checksums
a2f7f4483c9bd24f374ceda9aafbc66d65e10777415f8f79b18de7ddd8b403e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.12

Release history Release notifications | RSS feed

2.3.1

2 release files

2.1.0

2 release files

2.0.1

2 release files

1.47.0

2 release files

1.46.0

2 release files

1.45.0

2 release files

1.44.1

2 release files

1.44.0

2 release files

1.43.0

2 release files

1.42.0

2 release files

1.41.1

2 release files

1.38.0

2 release files

1.37.0

2 release files

1.36.0

2 release files

1.35.0

2 release files

1.31.0

2 release files

1.30.0

2 release files

1.29.0

2 release files

1.28.0

2 release files

1.27.0

2 release files

1.26.0

2 release files

1.20.0

2 release files

1.19.0

2 release files

1.17.0

2 release files

1.16.0

2 release files

1.15.0

2 release files

1.14.2

2 release files

1.10.2

2 release files

1.10.1

2 release files

1.10.0

2 release files

1.9.0

2 release files

1.8.1

2 release files

1.8.0

2 release files

1.7.0

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

This release

1.3.0 This release

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page