Thresh

SDKs

Official SDKs for Python (PyPI, Python 3.9+, one dependency) and JavaScript/TypeScript (npm, Node 18+, zero dependencies, fully typed). Same surface, same names on both registries; the toggle switches every example on this page.

pip install thresh-sdk

Package pages: thresh-sdk on PyPI and thresh-sdk on npm. Source on GitHub: Python and JavaScript/TypeScript, read-only mirrors of the packages above.

The whole loop

from thresh import Thresh

client = Thresh(api_key="th_live_...")

doc = client.upload(
    "contract.pdf",
    fields=["purchase_price", "closing_date", "buyer_name"],
    tables=[{"name": "monthly_charges", "columns": ["item", "qty", "mrc"]}],
    questions=["Is the sale contingent on financing?"],
)
result = client.wait(doc.id)

result.fields["purchase_price"]   # "399900"
result.tables["monthly_charges"]  # [{"item": ..., "qty": ..., "mrc": ...}]
result.answer("Is the sale contingent on financing?")  # "Yes"

Auto-extraction

Skip the schema entirely and the engine discovers it, returning fields and tables it named itself:

doc = client.upload("mystery.pdf")   # no schema arguments
result = client.wait(doc.id)
result.fields                        # {"invoice_number": "INV-2026-001", ...}

Templates

Save a schema once, run it across every similar document. Auto-extract a sample, keep the fields you want, and:

client.create_template("invoices", fields=["invoice_number", "total_due"])

doc = client.upload("next-invoice.pdf", template="invoices")

client.templates()          # list saved templates
client.delete_template(id)  # remove one

Retries and webhooks

Pass an idempotency key (idempotency_key in Python, idempotencyKey in TypeScript) to make upload retries safe. If you registered a webhook endpoint, verify deliveries with the built-in helper:

from thresh import verify_webhook_signature

ok = verify_webhook_signature(secret, request.headers["Thresh-Signature"], request.body)

Errors

Failures raise ThreshError carrying the HTTP status, the API error type (.error_type in Python, .errorType in TypeScript), the message, and the request id; include the request id when you write to support@usethresh.com and we can trace the exact call.