Skip to main content

ScrapeGraph Python SDK for API

Project description

🌐 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scrapegraph_py-1.4.3b2.tar.gz (105.8 kB view details)

Uploaded Source

Built Distribution

scrapegraph_py-1.4.3b2-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file scrapegraph_py-1.4.3b2.tar.gz.

File metadata

  • Download URL: scrapegraph_py-1.4.3b2.tar.gz
  • Upload date:
  • Size: 105.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for scrapegraph_py-1.4.3b2.tar.gz
Algorithm Hash digest
SHA256 38863c0509001d78cbd6185a305c7960b1aa863cd692805a446ba159f7105f35
MD5 71b4d2f6082c1d65b4e94985ec88a19e
BLAKE2b-256 3f1ee55a1c9437e52c7de7ee565faadb26eeb7791206c85e20261a1d881cd1dc

See more details on using hashes here.

File details

Details for the file scrapegraph_py-1.4.3b2-py3-none-any.whl.

File metadata

File hashes

Hashes for scrapegraph_py-1.4.3b2-py3-none-any.whl
Algorithm Hash digest
SHA256 f2dfaff2d0ae0174b2f548922af7d568d7ee649d8a11ac038133e96e13a63732
MD5 753b1920b6a8684b5c54e2ddc72dcf39
BLAKE2b-256 d687b387f2e53109d7155284d172e9505cb6fd59dd700fd45cfa5ffdf35145b4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page