Skip to main content
API v3 is available. This SDK targets the v2 API, which keeps working through its deprecation window. A new SDK major targeting v3 is in progress — see the v3 SDKs page and the v3 API reference.
The hand-written Python SDK for anyformat, built on httpx. It mirrors the TypeScript SDK and exposes a fluent builder over the same typed-graph workflow definition.

Installation

Requires Python 3.13 (the SDK pins to >=3.13,<3.14 today; this is expected to loosen before the official launch).
The PyPI distribution is named anyformat; the import path uses the dotted namespace anyformat.sdk (transport) and anyformat.workflow (schema factories).

Authentication

Pass the API key to Client, or set ANYFORMAT_API_KEY in the environment and read it from there.
See Authentication for how to mint an API key.

Basic usage

Full flow: build a workflow with a fluent builder, run a document, await the typed result.
The Result exposes typed scalar accessors via result.fields[name] for linear workflows (one untagged extraction) and the full envelope at result.raw for everything else (parse markdown, multiple extractions per split, classifications, splits).

Async usage

AsyncClient is the async sibling — every builder, handle, and result method has an async counterpart.

Builder methods

All node types in the typed graph are exposed as fluent methods. parse is required; the others are optional and can be chained in any topology the API allows. Workflow.run(file=None, *, text=None) accepts either file: bytes | pathlib.Path | str (a file path) or text= (raw text — useful for emails / plain-text bodies). Exactly one must be set. Returns a Run handle; Run.wait(timeout=300, poll_interval=3) returns the Result.

Smart lookup

A smart-lookup field is resolved by matching the document against a reference file (a CSV/catalog) instead of being read off the page. Flag the field with source="smart_lookup", and pass the reference file to .extract(..., lookup_files=[...]) — the SDK reads each path and uploads it with the workflow. Here the model reads vendor_name, then resolves the canonical vendor_id from a vendor catalog:
source="smart_lookup" is accepted on every Schema.* factory. The looked-up field comes back in result.fields alongside the others — there’s no separate section for it. An extract with a lookup field but no lookup_files is rejected with 400. A smart-lookup field is overwritten by the lookup; use source="lookup_if_missing" to extract it from the document too and let the lookup fill it only where extraction found no value.

Managing workflows

The client lists and deletes the workflows on your account:
Both have async equivalents on AsyncClient: await client.list_workflows(...) returns list[AsyncWorkflow] and await client.delete_workflow(id) returns the id.

Reading results

See Response formats for the full shape of every section.

Error handling

The SDK raises typed exceptions you can catch:
APIError exposes .status_code, .error_code, and .detail. The wire-format error codes (e.g. EXTRACTION_FAILED, RATE_LIMITED) are documented at Errors.

Webhooks (not on the SDK surface yet)

Client doesn’t expose webhook endpoints today. Until it does, register and delete webhooks with httpx directly:
See Webhooks for the payload shape and signature verification.