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
| TypeScript | Python | PHP | |
|---|---|---|---|
| Package | @druckling/sdk | druckling | druckling/druckling-php |
| Runtime | Node.js 20+, Bun, Deno, Cloudflare Workers, Vercel Functions | Python 3.9+ | PHP 8.1+ with ext-curl and ext-json |
| HTTP layer | fetch (the runtime's, or one you pass in) | httpx | Built-in curl transport, or any PSR-18 client |
| Runtime dependencies | None | httpx (>=0.23,<1) | None |
| Clients | Promise-based | Sync Druckling and async AsyncDruckling | Synchronous |
| Packaging | ESM and CommonJS, bundled type declarations | Typed (py.typed), dataclass models | Composer, PSR-4, readonly typed models |
| Response fields | snake_case, exactly as in the API | snake_case attributes, datetime values | camelCase properties, DateTimeImmutable values |
TypeScript
@druckling/sdk for Node.js, Bun, Deno and edge runtimes.
Python
druckling with sync and async clients on httpx.
PHP
druckling/druckling-php with curl or any PSR-18 client.
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.tgzRender 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 resource | Endpoints | In the SDKs |
|---|---|---|
| Documents | create, get, list | Yes. PNG page and scale options (image) aren't supported yet. |
| Templates | list, get | Yes |
| Webhook endpoints | create, list, get, delete | Yes. The batch.completed event isn't in the SDKs' event types yet. |
| Embedded editor sessions | create, revoke | Yes |
| Batches | create, list, get, documents, cancel | Not yet: use the REST API (guide) |
| Share links | create, list, revoke | Not yet: use the REST API (guide) |
On top of the endpoints, each SDK adds:
| Task | TypeScript | Python | PHP |
|---|---|---|---|
| Wait for an async render | documents.wait(doc) | documents.wait(doc) | documents->wait($doc) |
| Download the file | documents.download(doc) | documents.download(doc), documents.download_to(doc, path) | documents->download($doc), documents->downloadTo($doc, $path) |
| Walk every page of a list | for await (const doc of documents.list()) | for doc in documents.list() | foreach ($druckling->documents->list() as $doc) |
| Verify a webhook | verifyWebhook(body, headers, secret) | verify_webhook(body, headers, secret) | Webhook::verify($body, $headers, $secret) |
| Sign a test webhook | signWebhook(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_KEYenvironment variable. It's sent asAuthorization: Bearer …. Creating a client without a key throws right away. - Base URL: passed to the constructor, or read from
DRUCKLING_BASE_URL, defaulting tohttps://druckling-nine.vercel.app. It works with or without a trailing/v1; the SDK adds/v1itself. - 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_limitedis retried for every request, including renders: a rate-limited request produced no file and counted nothing toward your quota.429 quota_exceededis 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 forGETandDELETErequests only.POSTrequests (rendering a document, creating a webhook endpoint or an editor session) are not retried after a5xx, 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.