# SDKs (/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](/docs/api-reference) 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 [#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`](https://www.python-httpx.org/) | 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 |

<Cards>
  <Card title="TypeScript" href="/docs/sdks/typescript">
    `@druckling/sdk` for Node.js, Bun, Deno and edge runtimes.
  </Card>
  <Card title="Python" href="/docs/sdks/python">
    `druckling` with sync and async clients on httpx.
  </Card>
  <Card title="PHP" href="/docs/sdks/php">
    `druckling/druckling-php` with curl or any PSR-18 client.
  </Card>
</Cards>

## Install [#install]

<Callout type="info" title="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.

</Callout>

```bash tab="TypeScript"
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
```

```bash tab="Python"
pip install "git+https://github.com/vulpery/druckling.git#subdirectory=src/integrations/sdk-python"
```

```bash tab="PHP"
git clone https://github.com/vulpery/druckling.git

# then, in your project
composer config repositories.druckling path /path/to/druckling/src/integrations/sdk-php
composer require druckling/druckling-php:@dev
```

## Render your first document [#render-your-first-document]

Every workspace starts with the `invoice-standard` template published, so this works with a fresh [test key](/docs/concepts/test-mode):

```ts tab="TypeScript"
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://…
```

```python tab="Python"
from druckling import Druckling

client = Druckling()  # reads DRUCKLING_API_KEY

document = client.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},
    },
)

print(document.status, document.url)  # rendered https://…
```

```php tab="PHP"
<?php

require __DIR__ . '/vendor/autoload.php';

use Druckling\Druckling;

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

$document = $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],
    ],
);

echo $document->status, ' ', $document->url; // rendered https://…
```

## What the SDKs cover [#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](/docs/api-reference/documents/create) | create, get, list | Yes. PNG page and scale options (`image`) aren't supported yet. |
| [Templates](/docs/api-reference/templates/get) | list, get | Yes |
| [Webhook endpoints](/docs/api-reference/webhooks/create) | create, list, get, delete | Yes. The `batch.completed` event isn't in the SDKs' event types yet. |
| [Embedded editor sessions](/docs/api-reference/embedded-editor/create) | create, revoke | Yes |
| [Batches](/docs/api-reference/batches/create) | create, list, get, documents, cancel | Not yet: use the REST API ([guide](/docs/guides/batches)) |
| [Share links](/docs/api-reference/share-links/create) | create, list, revoke | Not yet: use the REST API ([guide](/docs/concepts/share-links)) |

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 [#shared-behavior]

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

### Configuration [#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](/docs/concepts/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](/docs/guides/embedded-editor) instead.

### Retries [#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](/docs/concepts/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](/docs/api-reference/documents/list) 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 [#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](/docs/concepts/documents).

### Waiting for async renders [#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](/docs/guides/webhooks).

### Downloads [#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 [#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](/docs/concepts/errors) for the codes.

### Webhook verification [#webhook-verification]

Webhooks follow the [Standard Webhooks](https://www.standardwebhooks.com/) 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](/docs/guides/webhooks).

## Other integrations [#other-integrations]

<Cards>
  <Card title="MCP server" href="/docs/guides/mcp">
    Let AI assistants render documents and edit templates through Druckling's hosted MCP server.
  </Card>
  <Card title="n8n" href="/docs/guides/n8n">
    Render documents and react to document events in n8n workflows.
  </Card>
</Cards>
