pip install scrapegraph-py
# or
uv add scrapegraph-py
Quick Start
from scrapegraph_py import ScrapeGraphAI
# reads SGAI_API_KEY from env, or pass explicitly: ScrapeGraphAI(api_key="...")
sgai = ScrapeGraphAI()
result = sgai.scrape("https://example.com")
if result.status == "success":
print(result.data["results"]["markdown"]["data"])
else:
print(result.error)
Every method returns ApiResult[T] — no exceptions to catch:
@dataclass
class ApiResult(Generic[T]):
status: Literal["success", "error"]
data: T | None
error: str | None
elapsed_ms: int
🆚 Open Source vs Managed API
This SDK is a client for the managed cloud API. ScrapeGraphAI also ships an open-source library you can run yourself. This table explains the difference so you can pick the right one.
Open Source (scrapegraphai)
Managed API (this SDK)
What it is
A Python library you run yourself
A hosted cloud service you call via SDK
Where it runs
Your own infrastructure (self-hosted)
ScrapeGraphAI cloud
LLM
Bring your own (OpenAI, Groq, Gemini, Azure, local via Ollama)
Choose the open-source library if you want full control, on-prem/self-hosted data, local LLMs (Ollama), or fine-grained cost tuning — and you're happy to manage browsers, proxies and scaling yourself.
Choose the managed API (this SDK) if you want zero infrastructure, managed JS rendering & anti-bot, built-in Crawl and scheduled Monitor jobs, and the fastest path to production — billed per credit.
Extract structured data from a URL, HTML, or markdown using AI.
from scrapegraph_py import ScrapeGraphAI
sgai = ScrapeGraphAI()
res = sgai.extract(
prompt="Extract product names and prices",
url="https://example.com",
schema={"type": "object", "properties": {...}}, # optional
mode="reader", # optional
# Or pass html/markdown directly instead of url
)
search
Search the web and optionally extract structured data.
from scrapegraph_py import ScrapeGraphAI
sgai = ScrapeGraphAI()
res = sgai.search(
"best programming languages 2024",
num_results=5, # 1-20, default 3
format="markdown", # "markdown" | "html"
prompt="Extract key points", # optional, for AI extraction
schema={...}, # optional
time_range="past_week", # optional
location_geo_code="us", # optional
allowed_types=["text/html", "application/pdf"], # optional MIME allowlist
)
By default search accepts every supported content type, including PDFs, and processes up to 25
pages per PDF. You do not need to send processors or max_pages for this default. Use
allowed_types to restrict accepted MIME types. Only configure processors to override the cap;
PdfProcessor() also defaults to 25, while max_pages accepts 1–500, or -1 for no page limit.
crawl
Crawl a website and its linked pages.
from scrapegraph_py import ScrapeGraphAI, ScrapeMarkdownFormatEntry
sgai = ScrapeGraphAI()
# Start a crawl
start = sgai.crawl.start(
"https://example.com",
formats=[ScrapeMarkdownFormatEntry()],
max_pages=50,
max_depth=2,
max_links_per_page=10,
include_patterns=["/blog/*"],
exclude_patterns=["/admin/*"],
)
# Check status
status = sgai.crawl.get(start.data["id"])
pages = sgai.crawl.pages(start.data["id"], cursor=0, limit=50)
# Control
sgai.crawl.stop(crawl_id)
sgai.crawl.resume(crawl_id)
sgai.crawl.delete(crawl_id)
Python SDK for Firecrawl: search, scrape, parse, crawl, map, and interact with the web, run Agent and Monitor jobs, and search scientific papers (PubMed, bioRxiv, medRxiv, arXiv)