Skip to main content

DocuNext for Python

The official Python client for DocuNext: fill DOCX, DOTX and ODT templates with JSON data and get PDF, PDF/A, DOCX, ODT or PNG files back.

  • Typed responses (TypedDicts), errors and webhook events
  • Retries rate-limited requests and failed reads; never repeats a generation
  • Helpers to wait for async documents and batches, and to download files
  • Webhook signature verification
  • Python 3.10 or later. One dependency: httpx.

Install

pip install docunext

Quick start

Create an API key on the API keys page. Use a test key (dn_test_…) while you build: test documents are free and watermarked.

from docunext import DocuNext

client = DocuNext()  # reads DOCUNEXT_API_KEY, or pass api_key="dn_test_..."

template = client.templates.list()[0]
file = client.documents.generate(
    template["id"],
    {"customer_name": "Acme Pty Ltd", "items": [{"description": "Widget", "qty": 2}]},
    output_format="pdf",
)

with open(file.filename, "wb") as handle:
    handle.write(file.content)

template["sample_data"] shows the data a template expects, and template["data_schema"] is a JSON Schema for it.

Async documents

For long documents, generate in the background and wait, or let a webhook tell you when it is ready.

accepted = client.documents.generate_async(template_id, data)
document = client.documents.wait_for(accepted["id"])  # checks every 2 seconds, up to 2 minutes

if document["status"] == "completed":
    pdf = client.documents.download(accepted["id"])

Batches

Up to 100 documents from one template in one request:

batch = client.batches.create(
    template_id,
    [{"data": invoice, "output_filename": f"invoice-{invoice['number']}"} for invoice in invoices],
    output_format="pdf",
)

finished = client.batches.wait_for(batch["id"])

for document in finished["documents"]:
    if document["status"] == "completed":
        print(document["index"], document["download_url"])
    else:
        print(document["index"], document["error"])

Errors

Failed requests raise DocuNextError with the API's machine-readable code and HTTP status:

from docunext import DocuNextError

try:
    client.documents.generate(template_id, {})
except DocuNextError as error:
    if error.code == "missing_field":
        print(error.message)  # "Missing field: customer_name"
    else:
        raise

Every code is listed in the API reference. network_error (status 0) means the request could not reach DocuNext.

Webhooks

Check each webhook request against your endpoint's signing secret, using the raw request body:

import os

from flask import Flask, request
from docunext import DocuNextSignatureError, construct_webhook_event

app = Flask(__name__)


@app.post("/webhooks/docunext")
def docunext_webhook():
    try:
        event = construct_webhook_event(
            request.get_data(),
            request.headers.get("DocuNext-Signature"),
            os.environ["DOCUNEXT_WEBHOOK_SECRET"],
        )
    except DocuNextSignatureError:
        return "Invalid signature", 400

    if event["type"] == "document.completed":
        ...  # event["data"] is the document, with a download_url valid for an hour.

    return "", 200

verify_webhook_signature(raw_body, header, secret) returns True or False if you prefer to handle it yourself.

Options

DocuNext(
    api_key="dn_live_...",  # defaults to the DOCUNEXT_API_KEY environment variable
    timeout=60.0,  # seconds per request
    max_retries=2,  # rate limits always; reads also after server and network errors
    base_url="https://www.docunext.app",
    http_client=None,  # your own httpx.Client, for proxies
)

Use the client as a context manager (with DocuNext() as client:) or call client.close() when you are done.

License

MIT

Metadata

Release files for docunext 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for docunext 0.1.0
File Size Uploaded Provenance Actions
docunext-0.1.0.tar.gz 13.3 kB With provenance Details for docunext-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for docunext 0.1.0
File Interpreter ABI Platform Actions
docunext-0.1.0-py3-none-any.whl Python 3 none any Details for docunext-0.1.0-py3-none-any.whl

Total release size: 25.2 kB

Release files / docunext-0.1.0.tar.gz

Download URL docunext-0.1.0.tar.gz
Size 13.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d00a2802bacb7df49420f21ca04a18db07fa16acbae1c4dc7bc847217ef0044e
BLAKE2b-256 checksum
How to use checksums
a4d7e8b61637134968f4455c14112bd53247c23910c7610dbddce02084e442e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Release files / docunext-0.1.0-py3-none-any.whl

Download URL docunext-0.1.0-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5c95aa5345558cee725f9ca679fa5adcf596a06cbd4457e9b4fa084ac8a77335
BLAKE2b-256 checksum
How to use checksums
fa990479fe2e34001bb9cd82b019113ee8838c8b035a28fd7ba4eb12eeaf9b3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Security for docunext 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for docunext-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page