Skip to main content

Typed Python SDK for the DocJet document generation API - render branded PDFs and PNG images, verify webhook signatures.

Project description

docjet — Python SDK

Typed Python client for the DocJet document generation API. Send a template ID plus data, get back a branded PDF or PNG — built for AI agents and automation builders.

  • Typed — full type hints, ships py.typed (PEP 561)
  • One dependencyhttpx
  • Python 3.10+
  • Webhook signature verification built in — verify X-DocJet-Signature in one call

Install

pip install docjet

Quickstart

from docjet import DocJetClient

client = DocJetClient(api_key="binfra_your_key")

# Render a PDF — returns a signed download URL
result = client.render(
    template_id="invoice-ro",
    data={"client": "Demo SRL", "total": 1000},
)
print(result["url"])  # https://api.docjet.dev/dl/...

Get a free API key at docjet.dev — first render in under 5 minutes.

Verify webhook signatures (the differentiator)

When a render completes, DocJet POSTs to your webhook URL and signs every callback with an X-DocJet-Signature header:

X-DocJet-Signature: t=<unix-seconds>,v1=<hmac-sha256-hex>

Verify it in one call — constant-time comparison and a 5-minute replay window are handled for you:

from docjet import verify_webhook_signature

# Flask example — works the same in FastAPI, Django, etc.
@app.post("/webhooks/docjet")
def docjet_webhook():
    raw_body = request.get_data(as_text=True)        # RAW body, before JSON parsing
    header = request.headers.get("X-DocJet-Signature", "")

    if not verify_webhook_signature(raw_body, header, WEBHOOK_SECRET):
        return "invalid signature", 400

    payload = json.loads(raw_body)                    # now safe to trust
    print(payload["url"])
    return "", 204
  • Get your signing secret: GET /v1/keys/webhook-secret
  • Pass the raw request body — verifying a re-serialized body will fail
  • Tampered, expired (>300s old), or malformed signatures return False
  • Custom tolerance: verify_webhook_signature(body, header, secret, tolerance_seconds=600)

Full surface

client.render(template_id=..., data=..., options=...)        # PDF  -> {"url": ...}
client.render_image(template_id=..., data=..., width=1200, height=630)  # PNG -> {"url": ...}
client.list_templates()                                       # public, no auth
client.usage()                                                # current-period usage

Pass html=... instead of template_id=... to render your own HTML.

Error handling

Non-2xx responses raise DocJetError with the API error code and HTTP status:

from docjet import DocJetClient, DocJetError

try:
    client.render(template_id="invoice-ro", data={...})
except DocJetError as e:
    print(e.code)         # e.g. "QUOTA_EXCEEDED"
    print(e.status_code)  # e.g. 429
Code Status Meaning
AUTH_INVALID 401 Missing or invalid API key
PAYLOAD_INVALID 400/422 Bad request body or template_id
TEMPLATE_NOT_FOUND 404 Unknown template_id
RATE_LIMITED 429 Too many requests per minute
QUOTA_EXCEEDED 429 Monthly render quota used up
CONCURRENCY_EXCEEDED 429 Too many simultaneous renders
INTERNAL_ERROR 5xx Server-side failure

Invalid template_id values are rejected locally (no network call) with PAYLOAD_INVALID / 422 — template IDs must match ^[a-z0-9][a-z0-9-]{0,63}$.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docjet-1.0.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docjet-1.0.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file docjet-1.0.0.tar.gz.

File metadata

  • Download URL: docjet-1.0.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.6

File hashes

Hashes for docjet-1.0.0.tar.gz
Algorithm Hash digest
SHA256 305c22210e5b63fa6447530099ce776882137dceae67fdfa7ade7bd08680e69b
MD5 de70e377fedff08f6896bd2f1355d588
BLAKE2b-256 24960c3c340c8fa2e87ec5f4ec328a6486be418b9c2eaaf3853e8ffdd3e9b06f

See more details on using hashes here.

File details

Details for the file docjet-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: docjet-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.6

File hashes

Hashes for docjet-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d2581551b9cc962bbe8d34565a33a36817490d4647e07a93fcf91c919d19829f
MD5 177248f876727e2c8ec97741221d6c2b
BLAKE2b-256 e3acd6812709f588ee4068a5922274876d4bc5881b191d2d8cb5ddbf8318c2b4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page