spidra-fastapi) brings the full Spidra API into FastAPI with idiomatic dependency injection, native async/await, a pre-built APIRouter that auto-documents itself in Swagger UI, HMAC-verified webhook dependencies, and a global proxy for cases where DI feels like overhead.
Installation
Get your API key from app.spidra.io under API Keys.
Store it as an environment variable. Never hardcode it.
Configuration
Set environment variables before starting your app:Two integration styles
spidra-fastapi offers two approaches. Both work, and you can mix them freely.
Option A — Dependency injection (recommended)
get_async_spidra and get_spidra are ready-made FastAPI dependencies. They create (or reuse) a scoped client on each request. This is the idiomatic FastAPI approach and makes unit testing easy — just override the dependency.
Option B — Global proxy
For scripts, background tasks, or simple routes where passing DI is cumbersome, import the globalspidra proxy directly:
spidra.async_client returns the async Spidra client. spidra.scrape(...), spidra.search(...), etc. are also available as synchronous shortcuts on the proxy.
Scraping
schema:
to_dict() recursively converts Spidra dataclasses and nested objects to plain dicts, ready to return from FastAPI routes.
Searching
sources: "web", "news", "images", "videos", "research", "developer". Defaults to ["web"].
Crawling
Mapping
Batch scraping
Parsing documents
Webhooks
Spidra sends signed webhook events to your endpoint.spidra-fastapi ships two webhook dependencies.
verify_spidra_webhook_json — validated JSON dict
The simplest approach. Validates the HMAC-SHA256 signature from X-Spidra-Signature and returns the parsed payload:
verify_spidra_webhook — raw bytes
When you need the raw body (e.g. to re-verify yourself or pass it elsewhere):
HTTPException(401) automatically if the signature is missing or invalid.
Event listeners
Register handlers that fire whenspidra.dispatch_event() is called:
Pydantic webhook model
SpidraWebhookEvent is a Pydantic model for strongly typed webhook payloads:
Advanced dependency injection
UseSpidraDependency to configure a scoped client with specific credentials, useful when handling multiple Spidra accounts in the same app:
dep.get_async() returns an AsyncSpidra client; dep.get_sync() returns a synchronous Spidra client.
Pre-built APIRouter
Mount all Spidra REST endpoints into your app in one line, auto-documented in OpenAPI/Swagger:http://localhost:8000/docs to see the full interactive Swagger documentation.
Or use the default pre-built router:
Error handling
All Spidra exceptions inherit fromSpidraError and are re-exported from spidra_fastapi. Register them as exception handlers:
Flask
Flask extension with Blueprint routing,
flask spidra CLI, and HMAC webhook decorator.Django
Django integration with management commands, signals, and built-in URL routing.

