Skip to main content

deskew

Official Python SDK for the Deskew document extraction API. Send a PDF, Office file, image or email; get back Markdown, text, blocks, tables and fields.

  • Python 3.9+, one dependency (httpx)
  • Sync (Deskew) and async (AsyncDeskew) clients with the same surface
  • Typed results (ExtractResult, Table, Job, Usage, Extraction), typed errors
  • Extractors end to end: create, test set, test runs, publish, versions, rollback, suggest-from-document, starters, lookup lists
  • Retries with backoff on 429 / 5xx / connection errors, Retry-After honoured
  • Automatic Idempotency-Key so retries never bill twice
  • Webhook signature verification

Install

pip install deskew-sdk

Quickstart

from deskew_sdk import Deskew

client = Deskew()  # reads DESKEW_API_KEY

result = client.extract("invoice.pdf", output="json", fields=True, wait=True)
print(result.markdown)
for table in result.tables or []:
    print(table.csv)
print(result.fields)

extract() returns an ExtractResult when the document was processed inline (HTTP 200) and a Job when it was queued (202). wait=True polls the job for you.

out = client.extract(url="https://example.com/report.pdf", mode="async")
if isinstance(out, Job):
    result = client.jobs.wait(out.id, poll_timeout=900)

Extractors

An extractor is a named, versioned definition of one kind of document and the JSON you want out of it. Create it, prove it on a test set, publish, then pass extractor= to extract().

from deskew_sdk import Deskew, ExtractorTestsFailing

client = Deskew()

# 1. Create a draft (or clone a starter: client.extractors.create("hospital-invoice", from_starter="hospital-invoice"))
client.extractors.create(
    "hospital-invoice",
    {
        "title": "Hospital invoice",
        "document": {
            "must_contain": ["itemised charges", "a total"],
            "reject_if": ["a prescription"],
        },
        "fields": [
            {"name": "invoice_number", "type": "string", "required": True, "aliases": ["Bill No"]},
            {"name": "total", "type": "money", "required": True},
            {
                "name": "line_items",
                "type": "group",
                "fields": [
                    {"name": "description", "type": "string"},
                    {"name": "amount", "type": "money"},
                ],
            },
        ],
        "rules": [
            {
                "id": "items_sum",
                "check": "abs(sum(line_items[].amount) - total) <= 1",
                "message": "Line items do not add up",
            }
        ],
    },
)

# 2. Test: attach samples with the expected output, run the set, read the per-field diff
client.extractors.test_documents.add(
    "hospital-invoice",
    "samples/bill-0912.pdf",
    expected={"invoice_number": "INV-2026/0912", "total": 29800},
)
run = client.extractors.test_runs.start("hospital-invoice")
run = client.extractors.test_runs.wait("hospital-invoice", run.id)
print(run.summary.field_accuracy, run.summary.worst_fields)

# 3. Publish (refused with ExtractorTestsFailing while the test set fails; force=True overrides)
try:
    version = client.extractors.publish("hospital-invoice", notes="first version")
except ExtractorTestsFailing as e:
    print(e.test_summary.failed, "documents fail; run", e.test_run_id)
    raise

# 4. Extract
result = client.extract(
    "bill.pdf", extractor="hospital-invoice", wait=True
)  # or "hospital-invoice@3", "@draft"
ex = result.extraction
print(ex.status, ex.data["total"], ex.evidence["total"].page, [f.rule for f in ex.flags])

client.extractors also has list, get(name, version=, draft=), save_draft, validate, versions, version, rollback, archive, runs / iter_runs and suggest(file, wait=True) (propose a definition from a sample document). client.starters.list() / .get(id) read the Deskew-maintained definitions; client.lists.put(name, csv, key=) / .get / .download / .remove manage the lookup lists that rules match with lookup(). The schema= argument and client.schemas still work but are deprecated aliases for extractors.

Packets

A packet is several documents submitted together: each is routed to (or assigned) an extractor, and a packet definition names the roles they fill plus cross-document rules. client.packets wraps /v1/packets, client.packets.definitions the definitions and client.packet_starters the Deskew-maintained definitions to clone.

from deskew_sdk import Deskew, PacketTimeout

client = Deskew()

# A definition: roles (each an extractor you have published) and cross-document rules
client.packets.definitions.create(
    "health-claim",
    {
        "title": "Health claim packet",
        "roles": {
            "claim": {"extractor": "health-claim-form", "min": 1, "max": 1},
            "bill": {"extractor": "hospital-invoice", "min": 1, "max": 1},
            "pharmacy_bills": {"extractor": "pharmacy-bill", "min": 0, "max": None},
        },
        "rules": [
            {
                "id": "claimed_matches_bill",
                "check": "abs(claim.claimed_total - bill.total) <= 1",
                "message": "Claimed amount differs from the bill",
            }
        ],
    },
)  # or: create("health-claim", from_starter="health-claim")

# Submit three files as one packet and wait for it (202, then polled)
try:
    packet = client.packets.create(
        [
            "claim-form.pdf",
            "final-bill.pdf",
            "pharmacy-1.jpg",
        ],  # paths, open files or (name, bytes)
        packet="health-claim",
        assignments={"claim-form.pdf": "health-claim-form"},  # skip routing for this one
        wait=True,
    )
except PacketTimeout as e:
    print("still", e.packet.status)
    raise

print(packet.status)  # "completed", "flagged", "failed" or "canceled"
print(packet.data["bill"]["total"], packet.data["pharmacy_bills"])
for doc in packet.documents:
    print(
        doc.file_name,
        doc.role,
        doc.extractor,
        doc.routing.confidence,
        doc.extraction and doc.extraction.status,
    )
for flag in packet.flags:
    print(flag.severity, flag.rule, flag.message, flag.fields)

client.packets also has list(status=, limit=, starting_after=) / iter, get, cancel and wait(id, timeout=1800, interval=2); client.packets.definitions has list(include_archived=), create, get, update (returns valid plus problems; nothing is stored when invalid) and archive; client.packet_starters.list() / .get(id). A packet.completed webhook carries the packet without data.

Errors

from deskew_sdk import Deskew, DeskewError, DocumentError, RateLimitError

try:
    result = client.extract("scan.pdf", wait=True)
except DocumentError as e:  # password_protected, corrupt_file, ...
    print(e.code, e.message)
except RateLimitError as e:
    print("slow down", e.retry_after)
except DeskewError as e:
    print(e.status, e.code, e.request_id)
Class When
AuthenticationError 401
ForbiddenError 403
QuotaExceededError 402
NotFoundError 404
RateLimitError 429 (.retry_after)
DocumentError 4xx with type: document_error
InvalidRequestError any other 4xx
ExtractorTestsFailing 409 extractor_tests_failing on publish (.test_summary, .test_run_id)
APIError 5xx
APIConnectionError / APITimeoutError no response
JobFailed / JobTimeout raised by wait
TestRunTimeout raised by extractors.test_runs.wait

Webhooks

from deskew_sdk import webhooks, SignatureVerificationError

event = webhooks.verify(raw_body, request.headers["Deskew-Signature"], SECRET)

See examples/ for a webhook receiver and the SDK docs.

Development

uv sync
uv run pytest
uv run ruff check .
uv run mypy

MIT licence.

Metadata

Release files for deskew-sdk 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for deskew-sdk 0.1.1
File Size Uploaded Provenance Actions
deskew_sdk-0.1.1.tar.gz 49.6 kB With provenance Details for deskew_sdk-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for deskew-sdk 0.1.1
File Interpreter ABI Platform Actions
deskew_sdk-0.1.1-py3-none-any.whl Python 3 none any Details for deskew_sdk-0.1.1-py3-none-any.whl

Total release size: 84.1 kB

Release files / deskew_sdk-0.1.1.tar.gz

Download URL deskew_sdk-0.1.1.tar.gz
Size 49.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2fc4a38b27403881d7ce019f10db8ed7a56c904353da2ba52604bde0fd48ad81
BLAKE2b-256 checksum
How to use checksums
a1a6e1837411bf96f8a3bdab5a39cdae48ea1aedd68204f799ab7faa56ef9965
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

Release files / deskew_sdk-0.1.1-py3-none-any.whl

Download URL deskew_sdk-0.1.1-py3-none-any.whl
Size 34.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a4a2cc03075661d97060b07c6da31ead3df873e9210835eba6fe9df8d49fe6cf
BLAKE2b-256 checksum
How to use checksums
4e84381999fd1956eb475ffbd907d67b488b6e4aa5fb89a0dda05fee94a3cb19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

Security for deskew-sdk 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for deskew_sdk-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page