|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +**scrapegraph-py** is the official Python SDK for the ScrapeGraph AI API. It provides a Python client for intelligent web scraping powered by AI. |
| 8 | + |
| 9 | +## Repository Structure |
| 10 | + |
| 11 | +``` |
| 12 | +scrapegraph-py/ |
| 13 | +├── scrapegraph_py/ # Python SDK source |
| 14 | +├── tests/ # Test suite |
| 15 | +├── examples/ # Usage examples |
| 16 | +├── docs/ # MkDocs documentation |
| 17 | +├── cookbook/ # Tutorials and recipes |
| 18 | +└── .github/workflows/ # CI/CD |
| 19 | +``` |
| 20 | + |
| 21 | +## Tech Stack |
| 22 | + |
| 23 | +- **Language**: Python 3.10+ |
| 24 | +- **Package Manager**: uv (recommended) or pip |
| 25 | +- **Core Dependencies**: requests, pydantic, python-dotenv, aiohttp |
| 26 | +- **Testing**: pytest, pytest-asyncio, pytest-mock, aioresponses |
| 27 | +- **Code Quality**: ruff |
| 28 | +- **Build**: hatchling |
| 29 | +- **Release**: semantic-release |
| 30 | + |
| 31 | +## Commands |
| 32 | + |
| 33 | +```bash |
| 34 | +# Install |
| 35 | +uv sync |
| 36 | + |
| 37 | +# Test |
| 38 | +uv run pytest tests/ -v |
| 39 | + |
| 40 | +# Format & lint |
| 41 | +uv run ruff format src tests |
| 42 | +uv run ruff check src tests --fix |
| 43 | + |
| 44 | +# Build |
| 45 | +uv build |
| 46 | +``` |
| 47 | + |
| 48 | +## Before completing any task |
| 49 | + |
| 50 | +Always run these commands before committing or saying a task is done: |
| 51 | + |
| 52 | +```bash |
| 53 | +uv run ruff format src tests |
| 54 | +uv run ruff check src tests --fix |
| 55 | +uv build |
| 56 | +uv run pytest tests/ -v |
| 57 | +``` |
| 58 | + |
| 59 | +No exceptions. |
| 60 | + |
| 61 | +## Architecture |
| 62 | + |
| 63 | +**Core Components:** |
| 64 | + |
| 65 | +1. **Clients** (`scrapegraph_py/`): |
| 66 | + - `client.py` - Sync client |
| 67 | + - `async_client.py` - Async client |
| 68 | + |
| 69 | +2. **Models** (`scrapegraph_py/models/`): |
| 70 | + - Pydantic models for request/response validation |
| 71 | + |
| 72 | +3. **Config** (`scrapegraph_py/`): |
| 73 | + - `config.py` - API base URL, timeouts |
| 74 | + - `exceptions.py` - Custom exceptions |
| 75 | + |
| 76 | +## API Endpoints |
| 77 | + |
| 78 | +| Endpoint | Method | Purpose | |
| 79 | +|----------|--------|---------| |
| 80 | +| SmartScraper | `smartscraper()` | AI data extraction | |
| 81 | +| SearchScraper | `searchscraper()` | Multi-URL search | |
| 82 | +| Markdownify | `markdownify()` | HTML to Markdown | |
| 83 | +| Crawler | `crawler()` | Sitemap & crawling | |
| 84 | +| AgenticScraper | `agentic_scraper()` | Browser automation | |
| 85 | +| Scrape | `scrape()` | Basic HTML fetch | |
| 86 | +| Credits | `get_credits()` | Balance check | |
| 87 | + |
| 88 | +## Adding New Endpoint |
| 89 | + |
| 90 | +1. Add models in `scrapegraph_py/models/` |
| 91 | +2. Add sync method to `client.py` |
| 92 | +3. Add async method to `async_client.py` |
| 93 | +4. Export in `models/__init__.py` |
| 94 | +5. Add tests in `tests/` |
| 95 | + |
| 96 | +## Environment Variables |
| 97 | + |
| 98 | +- `SGAI_API_KEY` - API key for authentication |
| 99 | + |
| 100 | +## Usage |
| 101 | + |
| 102 | +```python |
| 103 | +from scrapegraph_py import Client |
| 104 | + |
| 105 | +client = Client(api_key="your-key") |
| 106 | +response = client.smartscraper( |
| 107 | + website_url="https://example.com", |
| 108 | + user_prompt="Extract title" |
| 109 | +) |
| 110 | +print(response.result) |
| 111 | +``` |
| 112 | + |
| 113 | +## Links |
| 114 | + |
| 115 | +- [API Docs](https://docs.scrapegraphai.com) |
| 116 | +- [PyPI](https://pypi.org/project/scrapegraph-py/) |
0 commit comments