Runnable async-first scripts exercising every capability from the TUTORIAL. Each example is self-contained except for shared fixtures in examples_helpers.py.
| # | Script | What it shows |
|---|---|---|
| 1 | 01_first_extraction.py |
Smallest async extraction with a hand-written DocumentTypeSpec. |
| 2 | 02_typed_schema_and_rules.py |
Realistic invoice schema with validators + business rules + dry-run validate. |
| 3 | 03_async_extraction_with_wait.py |
Submit via extractions.create, poll wait_for_completion, fetch with extractions.get_result. |
| 4 | 04_webhook_receiver_fastapi.py |
FastAPI app that verifies X-Flydocs-Signature and dispatches on the four v1 event types. |
| 5 | 05_error_handling.py |
Branching on RFC 7807 v1 codes (timeout, file_too_large, validation_failed) + sync→async fallback. |
| 6 | 06_sync_facade.py |
The synchronous facade (Client) for non-async callers. |
task docker:up:test # spin up flydocs + mock-llm at http://localhost:8080
# Then run any example. Examples 2/3/5/6 share fixtures via PYTHONPATH:
uv run python sdks/python/examples/01_first_extraction.py path/to/invoice.pdf
PYTHONPATH=sdks/python/examples \
uv run python sdks/python/examples/02_typed_schema_and_rules.py path/to/invoice.pdf
PYTHONPATH=sdks/python/examples \
uv run python sdks/python/examples/03_async_extraction_with_wait.py path/to/invoice.pdfThe mock LLM accepts any document and returns a fixed schema-compatible response, so the examples work end-to-end without an Anthropic / OpenAI key.
If you migrated from the v0 SDK, every example here highlights the breaking changes:
- Request bodies use
files(wasdocuments) anddocument_types(wasdocs). - Responses nest
model/latency_ms/traceunderresult.pipeline. documents[*].field_groups[*].fieldsreplaces the v0documents[*]["fields"][*]["fieldGroupFields"]dict walk.- Async endpoints are
POST /api/v1/extractionsetc. (was/api/v1/jobs). - Statuses are lowercase (
queued,succeeded, ...). - Webhook payloads use a single
EventEnvelopewith a dottedevent_type(extraction.completed, ...).