D
Druckling
Docs

SDKs

Official Druckling client libraries for TypeScript, Python and PHP, what they cover and how they behave.

Druckling has official SDKs for TypeScript/JavaScript, Python and PHP. They wrap the REST API with typed models and errors, and add the parts you would otherwise write yourself: retries with backoff, auto-paging, waiting for async renders, downloading files, and verifying webhook signatures.

Choose an SDK

TypeScriptPythonPHP
Package@druckling/sdkdrucklingdruckling/druckling-php
RuntimeNode.js 20+, Bun, Deno, Cloudflare Workers, Vercel FunctionsPython 3.9+PHP 8.1+ with ext-curl and ext-json
HTTP layerfetch (the runtime's, or one you pass in)httpxBuilt-in curl transport, or any PSR-18 client
Runtime dependenciesNonehttpx (>=0.23,<1)None
ClientsPromise-basedSync Druckling and async AsyncDrucklingSynchronous
PackagingESM and CommonJS, bundled type declarationsTyped (py.typed), dataclass modelsComposer, PSR-4, readonly typed models
Response fieldssnake_case, exactly as in the APIsnake_case attributes, datetime valuescamelCase properties, DateTimeImmutable values

Install

Registry packages are coming

The SDKs aren't on npm, PyPI or Packagist yet. Until they are, install them from the Druckling source repository as shown below. Each SDK page has the full steps.

git clone https://github.com/vulpery/druckling.git
cd druckling/src/integrations/sdk-typescript
npm install && npm run build && npm pack

# then, in your project
npm install /path/to/druckling-sdk-0.1.0.tgz

Render your first document

Every workspace starts with the invoice-standard template published, so this works with a fresh test key:

import Druckling from "@druckling/sdk";

const druckling = new Druckling(); // reads DRUCKLING_API_KEY

const document = await druckling.documents.create({
  template: "invoice-standard",
  data: {
    invoice: { number: "INV-2041", due_date: "2026-11-22" },
    customer: { name: "Northwind Ltd.", address: "12 Pier St, Leeds" },
    line_items: [{ description: "Design system audit", qty: 12, rate: 180, amount: 2160 }],
    totals: { subtotal: 2160, tax: 172.8, amount: 2332.8 },
  },
});

console.log(document.status, document.url); // rendered https://…

What the SDKs cover

The SDKs implement the API resources you use most. For the others, call the REST API directly with the same API key.

API resourceEndpointsIn the SDKs
Documentscreate, get, listYes. PNG page and scale options (image) aren't supported yet.
Templateslist, getYes
Webhook endpointscreate, list, get, deleteYes. The batch.completed event isn't in the SDKs' event types yet.
Embedded editor sessionscreate, revokeYes
Batchescreate, list, get, documents, cancelNot yet: use the REST API (guide)
Share linkscreate, list, revokeNot yet: use the REST API (guide)

On top of the endpoints, each SDK adds:

TaskTypeScriptPythonPHP
Wait for an async renderdocuments.wait(doc)documents.wait(doc)documents->wait($doc)
Download the filedocuments.download(doc)documents.download(doc), documents.download_to(doc, path)documents->download($doc), documents->downloadTo($doc, $path)
Walk every page of a listfor await (const doc of documents.list())for doc in documents.list()foreach ($druckling->documents->list() as $doc)
Verify a webhookverifyWebhook(body, headers, secret)verify_webhook(body, headers, secret)Webhook::verify($body, $headers, $secret)
Sign a test webhooksignWebhook(secret, id, timestamp, body)sign_webhook(secret, msg_id, timestamp, body)Webhook::sign($secret, $msgId, $timestamp, $body)

Shared behavior

The three SDKs follow the same rules, so you can move between them without surprises.

Configuration

  • API key: passed to the constructor, or read from the DRUCKLING_API_KEY environment variable. It's sent as Authorization: Bearer …. Creating a client without a key throws right away.
  • Base URL: passed to the constructor, or read from DRUCKLING_BASE_URL, defaulting to https://druckling-nine.vercel.app. It works with or without a trailing /v1; the SDK adds /v1 itself.
  • Mode: the key decides it. dr_test_… keys work in test mode, dr_live_… keys in live mode. See Test mode.

Keep API keys on your server. Never ship them to a browser or mobile app; for in-browser template editing, use embedded editor sessions instead.

Retries

Each request is retried up to 2 times by default (maxRetries / max_retries, 0 turns retries off):

  • 429 rate_limited is retried for every request, including renders: a rate-limited request produced no file and counted nothing toward your quota.
  • 429 quota_exceeded is never retried. Your plan's document quota is used up, so the SDK throws a quota error right away. See Plans and limits.
  • 408, 5xx, timeouts and connection errors are retried for GET and DELETE requests only.
  • POST requests (rendering a document, creating a webhook endpoint or an editor session) are not retried after a 5xx, a timeout or a connection error. The API has no idempotency keys yet, so a retry could render the document twice and count twice toward your quota. Catch the error and decide yourself, for example by listing recent documents first.

Waits grow exponentially from 0.5 seconds to at most 8 seconds, with jitter. When a response carries a Retry-After header of 60 seconds or less, the SDK waits that long instead; a longer Retry-After is returned to you as an error without retrying.

Timeouts

The default timeout is 60 seconds per attempt; each SDK's page explains exactly what it covers. Synchronous renders happen inside the request, so leave room for large documents, or render them asynchronously.

Waiting for async renders

With async: true (async_=True in Python), documents.create returns at once with status queued. The wait helper polls the document every second for up to 120 seconds. It returns the document once it's rendered, throws a document-failed error when it ends failed or expired, and a wait-timeout error when time runs out. Every poll is an API request, so for long queues prefer webhooks.

Downloads

The download helpers fetch the file (PDF, PNG or XML) from the document's signed url. Your API key isn't sent to that URL. Pass a document ID instead of a document to get a fresh signed URL first; signed URLs stop working after at most 7 days.

Errors

Every SDK has one error class per kind of failure, all under one base class. API errors carry the HTTP status, Druckling's error code, the message, the offending field, a list of field errors (for example every missing field of a payload), the ID of the failed document for validation failures, and the request ID. See Errors for the codes.

Webhook verification

Webhooks follow the Standard Webhooks spec. The verify helpers check the HMAC-SHA256 signature against the raw request body, reject timestamps more than 5 minutes off, accept any of several signatures (so secret rotation needs no downtime), and return the parsed event. See Webhooks.

Other integrations

On this page