Skip to main content
The Spidra Flask integration (spidra-flask) brings the full Spidra API — scrape, batch scrape, search, crawl, map, parse, templates, presets, and monitors — natively into Flask. It follows Flask extension conventions: direct initialization or the Application Factory pattern, a pre-built Blueprint exposing REST endpoints, an event dispatcher for webhooks, and a flask spidra CLI group for terminal use.

Installation

Requires Python 3.9+ and Flask 2.3+.
Get your API key from app.spidra.io under API Keys. Store it in an environment variable or your Flask app config. Never hardcode it.

Configuration

Configure credentials via environment variables or directly in app.config:
Or in your Flask config:
Flask app config takes precedence over environment variables.

Initialization

spidra-flask supports both styles.

Direct initialization

Application Factory pattern

SpidraFlask is an alias for Spidra if you prefer a more explicit name.

Scraping

spidra.scrape() extracts content from a URL — plain markdown or structured JSON — with browser rendering, CAPTCHA bypass, and optional residential proxies:
For structured extraction, pass a JSON Schema and a prompt:
spidra_jsonify() recursively serializes Spidra dataclasses to JSON, including nested stats objects. It accepts any mix of dicts, lists, and Spidra objects.

Searching

Available sources: "web", "news", "images", "videos", "research", "developer". Defaults to ["web"].

Crawling

Crawl an entire site recursively and extract structured data from every page:
For large crawls, submit without waiting and poll:

Mapping

Discover all URLs on a domain without scraping page bodies:

Batch scraping

Submit up to 50 URLs in one request and process them in parallel:

Parsing documents

Parse PDFs, Word, Excel, and other documents into Markdown or structured JSON:
Pass a URL to fetch and parse remotely:

Async Flask views

Flask 2.0+ supports native async def views. Access the async client via spidra.async_client:

Webhooks

Spidra sends signed webhook events (e.g. crawl.page, crawl.completed) to your endpoint. Use the @spidra_webhook_required decorator to verify HMAC-SHA256 signatures automatically:
The decorator reads SPIDRA_WEBHOOK_SECRET from config, verifies the X-Spidra-Signature header against the raw body, and returns 401 if the signature is invalid.

Event listeners

Register handlers that fire automatically when a verified webhook arrives. Pair this with the Blueprint’s built-in /spidra/webhooks endpoint:
Dispatch manually from your own endpoint:

Pre-built Blueprint

Register a Blueprint that exposes a complete Spidra REST API under /spidra:
Or with a custom prefix:
The Blueprint exposes:

Flask CLI

spidra-flask adds a flask spidra CLI group:

Error handling

All Spidra exceptions inherit from SpidraError and are re-exported from spidra_flask:
See the Python SDK for the full exception hierarchy.

FastAPI

Native async-first integration with dependency injection, Pydantic models, and OpenAPI docs.

Django

Full Django integration with management commands, Django Signals, and built-in URL routing.