Skip to main content

PyPI Package

PyPI version

Python Support

Python Support

Source on GitHub

Issues, PRs, and the changelog
These docs cover scrapegraph-py ≥ 2.1.0 and require Python ≥ 3.12. Earlier 1.x releases expose the deprecated v1 API and point to a different backend — none of the snippets on this page work there. The 2.0.x series used typed request wrappers (ScrapeRequest, ExtractRequest, …); 2.1.0 removed those wrappers in favour of direct positional/keyword arguments, so upgrade if you are pinned to 2.0.x.

Installation

What’s New in v2

  • Complete rewrite built on Pydantic v2 + httpx.
  • Client rename: ClientScrapeGraphAI, AsyncClientAsyncScrapeGraphAI.
  • Direct arguments (v2.1.0): every method accepts positional/keyword args — no more ScrapeRequest/ExtractRequest/… wrappers.
  • ApiResult[T] wrapper: no exceptions on API errors — every call returns status: "success" | "error", data, error, and elapsed_ms.
  • Nested resources: sgai.crawl.*, sgai.monitor.*, sgai.history.*.
  • camelCase on the wire, snake_case in Python: automatic via Pydantic’s alias_generator.
  • Removed: markdownify(), agenticscraper(), sitemap(), feedback() — use scrape() with the appropriate format entry instead.
v2 is a breaking release. See the Migration Guide if you’re upgrading from v1.

Quick Start

ApiResult

Every method returns ApiResult[T] — no try/except needed for API errors:

Environment Variables

The client supports context managers for automatic session cleanup:

Services

Scrape

Fetch a page in one or more formats (markdown, html, screenshot, json, links, images, summary, branding).

scrape() parameters

Format entries

Duplicate type entries in formats are rejected by a Pydantic validator.

Extract

Run structured extraction against a URL, HTML, or markdown using AI.
Using a Pydantic model as the schema
schema= is a JSON Schema dict. Any Pydantic BaseModel produces one via model_json_schema(), so you can define the desired shape once and reuse it to validate the response client-side.
The same pattern works for JsonFormatConfig(schema=...) in scrape() and for search(schema=...).

extract() parameters

*At least one of url, html, or markdown is required.
Run a web search and optionally extract structured data from the results.

search() parameters

Crawl

Crawl a site and its linked pages asynchronously. Access via the sgai.crawl resource.

crawl.start() parameters

Monitor

Scheduled extraction jobs. Access via the sgai.monitor resource.

monitor.activity() — poll tick history

Paginate through the per-run ticks a monitor has produced (what changed on each scheduled run).
monitor.activity() accepts limit (1–100, default 20) and optional cursor for pagination. Each MonitorTickEntry exposes id, created_at, status, changed, elapsed_ms, and a diffs model with per-format deltas.

monitor.create() parameters

History

Fetch recent request history. Access via the sgai.history resource.

Credits / Health

Configuration Objects

FetchConfig

Controls how pages are fetched. See the proxy configuration guide for details on modes and geotargeting.

Async Support

Every sync method has an async equivalent on AsyncScrapeGraphAI:

Support

GitHub

Report issues and contribute to the SDK

Email Support

Get help from our development team