docunext 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,54 @@
1
+ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2
+
3
+ # dependencies
4
+ /node_modules
5
+ /.pnp
6
+ .pnp.*
7
+ .yarn/*
8
+ !.yarn/patches
9
+ !.yarn/plugins
10
+ !.yarn/releases
11
+ !.yarn/versions
12
+
13
+ # testing
14
+ /coverage
15
+
16
+ # next.js
17
+ /.next/
18
+ /out/
19
+
20
+ # production
21
+ /build
22
+
23
+ # misc
24
+ .DS_Store
25
+ *.pem
26
+
27
+ # debug
28
+ npm-debug.log*
29
+ yarn-debug.log*
30
+ yarn-error.log*
31
+ .pnpm-debug.log*
32
+
33
+ # env files (can opt-in for committing if needed)
34
+ .env*
35
+
36
+ # vercel
37
+ .vercel
38
+
39
+ # typescript
40
+ *.tsbuildinfo
41
+ next-env.d.ts
42
+ gotenberg-key.json
43
+ *.service-account.json
44
+ # SDK packages build and install their own files
45
+ packages/*/node_modules
46
+ packages/*/dist
47
+
48
+ # Python SDK local files
49
+ packages/*/.venv
50
+ packages/*/**/__pycache__
51
+ packages/*/.mypy_cache
52
+ packages/*/.pytest_cache
53
+ packages/*/*.egg-info
54
+ packages/*/src/*.egg-info
docunext-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DocuNext
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,170 @@
1
+ Metadata-Version: 2.5
2
+ Name: docunext
3
+ Version: 0.1.0
4
+ Summary: Official Python client for the DocuNext document generation API.
5
+ Project-URL: Homepage, https://www.docunext.app
6
+ Project-URL: Documentation, https://www.docunext.app/docs
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Keywords: api,document generation,docunext,docx,pdf,templates
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Topic :: Office/Business
16
+ Classifier: Typing :: Typed
17
+ Requires-Python: >=3.10
18
+ Requires-Dist: httpx<1,>=0.27
19
+ Requires-Dist: typing-extensions>=4.7; python_version < '3.11'
20
+ Provides-Extra: dev
21
+ Requires-Dist: mypy>=1.10; extra == 'dev'
22
+ Requires-Dist: pytest>=8; extra == 'dev'
23
+ Description-Content-Type: text/markdown
24
+
25
+ # DocuNext for Python
26
+
27
+ The official Python client for [DocuNext](https://www.docunext.app): fill DOCX, DOTX and ODT templates with JSON
28
+ data and get PDF, PDF/A, DOCX, ODT or PNG files back.
29
+
30
+ - Typed responses (TypedDicts), errors and webhook events
31
+ - Retries rate-limited requests and failed reads; never repeats a generation
32
+ - Helpers to wait for async documents and batches, and to download files
33
+ - Webhook signature verification
34
+ - Python 3.10 or later. One dependency: [httpx](https://www.python-httpx.org).
35
+
36
+ ## Install
37
+
38
+ ```bash
39
+ pip install docunext
40
+ ```
41
+
42
+ ## Quick start
43
+
44
+ Create an API key on the [API keys page](https://www.docunext.app/dashboard/api-keys). Use a test key
45
+ (`dn_test_…`) while you build: test documents are free and watermarked.
46
+
47
+ ```python
48
+ from docunext import DocuNext
49
+
50
+ client = DocuNext() # reads DOCUNEXT_API_KEY, or pass api_key="dn_test_..."
51
+
52
+ template = client.templates.list()[0]
53
+ file = client.documents.generate(
54
+ template["id"],
55
+ {"customer_name": "Acme Pty Ltd", "items": [{"description": "Widget", "qty": 2}]},
56
+ output_format="pdf",
57
+ )
58
+
59
+ with open(file.filename, "wb") as handle:
60
+ handle.write(file.content)
61
+ ```
62
+
63
+ `template["sample_data"]` shows the data a template expects, and `template["data_schema"]` is a JSON Schema for it.
64
+
65
+ ## Async documents
66
+
67
+ For long documents, generate in the background and wait, or let a webhook tell you when it is ready.
68
+
69
+ ```python
70
+ accepted = client.documents.generate_async(template_id, data)
71
+ document = client.documents.wait_for(accepted["id"]) # checks every 2 seconds, up to 2 minutes
72
+
73
+ if document["status"] == "completed":
74
+ pdf = client.documents.download(accepted["id"])
75
+ ```
76
+
77
+ ## Batches
78
+
79
+ Up to 100 documents from one template in one request:
80
+
81
+ ```python
82
+ batch = client.batches.create(
83
+ template_id,
84
+ [{"data": invoice, "output_filename": f"invoice-{invoice['number']}"} for invoice in invoices],
85
+ output_format="pdf",
86
+ )
87
+
88
+ finished = client.batches.wait_for(batch["id"])
89
+
90
+ for document in finished["documents"]:
91
+ if document["status"] == "completed":
92
+ print(document["index"], document["download_url"])
93
+ else:
94
+ print(document["index"], document["error"])
95
+ ```
96
+
97
+ ## Errors
98
+
99
+ Failed requests raise `DocuNextError` with the API's machine-readable `code` and HTTP `status`:
100
+
101
+ ```python
102
+ from docunext import DocuNextError
103
+
104
+ try:
105
+ client.documents.generate(template_id, {})
106
+ except DocuNextError as error:
107
+ if error.code == "missing_field":
108
+ print(error.message) # "Missing field: customer_name"
109
+ else:
110
+ raise
111
+ ```
112
+
113
+ Every code is listed in the [API reference](https://www.docunext.app/docs#errors). `network_error` (status 0) means
114
+ the request could not reach DocuNext.
115
+
116
+ ## Webhooks
117
+
118
+ Check each webhook request against your endpoint's signing secret, using the **raw** request body:
119
+
120
+ ```python
121
+ import os
122
+
123
+ from flask import Flask, request
124
+ from docunext import DocuNextSignatureError, construct_webhook_event
125
+
126
+ app = Flask(__name__)
127
+
128
+
129
+ @app.post("/webhooks/docunext")
130
+ def docunext_webhook():
131
+ try:
132
+ event = construct_webhook_event(
133
+ request.get_data(),
134
+ request.headers.get("DocuNext-Signature"),
135
+ os.environ["DOCUNEXT_WEBHOOK_SECRET"],
136
+ )
137
+ except DocuNextSignatureError:
138
+ return "Invalid signature", 400
139
+
140
+ if event["type"] == "document.completed":
141
+ ... # event["data"] is the document, with a download_url valid for an hour.
142
+
143
+ return "", 200
144
+ ```
145
+
146
+ `verify_webhook_signature(raw_body, header, secret)` returns `True` or `False` if you prefer to handle it yourself.
147
+
148
+ ## Options
149
+
150
+ ```python
151
+ DocuNext(
152
+ api_key="dn_live_...", # defaults to the DOCUNEXT_API_KEY environment variable
153
+ timeout=60.0, # seconds per request
154
+ max_retries=2, # rate limits always; reads also after server and network errors
155
+ base_url="https://www.docunext.app",
156
+ http_client=None, # your own httpx.Client, for proxies
157
+ )
158
+ ```
159
+
160
+ Use the client as a context manager (`with DocuNext() as client:`) or call `client.close()` when you are done.
161
+
162
+ ## Links
163
+
164
+ - [API reference](https://www.docunext.app/docs)
165
+ - [Template syntax](https://www.docunext.app/docs#template-syntax)
166
+ - [Making a template](https://www.docunext.app/docs/templates)
167
+
168
+ ## License
169
+
170
+ MIT
@@ -0,0 +1,146 @@
1
+ # DocuNext for Python
2
+
3
+ The official Python client for [DocuNext](https://www.docunext.app): fill DOCX, DOTX and ODT templates with JSON
4
+ data and get PDF, PDF/A, DOCX, ODT or PNG files back.
5
+
6
+ - Typed responses (TypedDicts), errors and webhook events
7
+ - Retries rate-limited requests and failed reads; never repeats a generation
8
+ - Helpers to wait for async documents and batches, and to download files
9
+ - Webhook signature verification
10
+ - Python 3.10 or later. One dependency: [httpx](https://www.python-httpx.org).
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ pip install docunext
16
+ ```
17
+
18
+ ## Quick start
19
+
20
+ Create an API key on the [API keys page](https://www.docunext.app/dashboard/api-keys). Use a test key
21
+ (`dn_test_…`) while you build: test documents are free and watermarked.
22
+
23
+ ```python
24
+ from docunext import DocuNext
25
+
26
+ client = DocuNext() # reads DOCUNEXT_API_KEY, or pass api_key="dn_test_..."
27
+
28
+ template = client.templates.list()[0]
29
+ file = client.documents.generate(
30
+ template["id"],
31
+ {"customer_name": "Acme Pty Ltd", "items": [{"description": "Widget", "qty": 2}]},
32
+ output_format="pdf",
33
+ )
34
+
35
+ with open(file.filename, "wb") as handle:
36
+ handle.write(file.content)
37
+ ```
38
+
39
+ `template["sample_data"]` shows the data a template expects, and `template["data_schema"]` is a JSON Schema for it.
40
+
41
+ ## Async documents
42
+
43
+ For long documents, generate in the background and wait, or let a webhook tell you when it is ready.
44
+
45
+ ```python
46
+ accepted = client.documents.generate_async(template_id, data)
47
+ document = client.documents.wait_for(accepted["id"]) # checks every 2 seconds, up to 2 minutes
48
+
49
+ if document["status"] == "completed":
50
+ pdf = client.documents.download(accepted["id"])
51
+ ```
52
+
53
+ ## Batches
54
+
55
+ Up to 100 documents from one template in one request:
56
+
57
+ ```python
58
+ batch = client.batches.create(
59
+ template_id,
60
+ [{"data": invoice, "output_filename": f"invoice-{invoice['number']}"} for invoice in invoices],
61
+ output_format="pdf",
62
+ )
63
+
64
+ finished = client.batches.wait_for(batch["id"])
65
+
66
+ for document in finished["documents"]:
67
+ if document["status"] == "completed":
68
+ print(document["index"], document["download_url"])
69
+ else:
70
+ print(document["index"], document["error"])
71
+ ```
72
+
73
+ ## Errors
74
+
75
+ Failed requests raise `DocuNextError` with the API's machine-readable `code` and HTTP `status`:
76
+
77
+ ```python
78
+ from docunext import DocuNextError
79
+
80
+ try:
81
+ client.documents.generate(template_id, {})
82
+ except DocuNextError as error:
83
+ if error.code == "missing_field":
84
+ print(error.message) # "Missing field: customer_name"
85
+ else:
86
+ raise
87
+ ```
88
+
89
+ Every code is listed in the [API reference](https://www.docunext.app/docs#errors). `network_error` (status 0) means
90
+ the request could not reach DocuNext.
91
+
92
+ ## Webhooks
93
+
94
+ Check each webhook request against your endpoint's signing secret, using the **raw** request body:
95
+
96
+ ```python
97
+ import os
98
+
99
+ from flask import Flask, request
100
+ from docunext import DocuNextSignatureError, construct_webhook_event
101
+
102
+ app = Flask(__name__)
103
+
104
+
105
+ @app.post("/webhooks/docunext")
106
+ def docunext_webhook():
107
+ try:
108
+ event = construct_webhook_event(
109
+ request.get_data(),
110
+ request.headers.get("DocuNext-Signature"),
111
+ os.environ["DOCUNEXT_WEBHOOK_SECRET"],
112
+ )
113
+ except DocuNextSignatureError:
114
+ return "Invalid signature", 400
115
+
116
+ if event["type"] == "document.completed":
117
+ ... # event["data"] is the document, with a download_url valid for an hour.
118
+
119
+ return "", 200
120
+ ```
121
+
122
+ `verify_webhook_signature(raw_body, header, secret)` returns `True` or `False` if you prefer to handle it yourself.
123
+
124
+ ## Options
125
+
126
+ ```python
127
+ DocuNext(
128
+ api_key="dn_live_...", # defaults to the DOCUNEXT_API_KEY environment variable
129
+ timeout=60.0, # seconds per request
130
+ max_retries=2, # rate limits always; reads also after server and network errors
131
+ base_url="https://www.docunext.app",
132
+ http_client=None, # your own httpx.Client, for proxies
133
+ )
134
+ ```
135
+
136
+ Use the client as a context manager (`with DocuNext() as client:`) or call `client.close()` when you are done.
137
+
138
+ ## Links
139
+
140
+ - [API reference](https://www.docunext.app/docs)
141
+ - [Template syntax](https://www.docunext.app/docs#template-syntax)
142
+ - [Making a template](https://www.docunext.app/docs/templates)
143
+
144
+ ## License
145
+
146
+ MIT
@@ -0,0 +1,43 @@
1
+ # Releasing the Python SDK
2
+
3
+ Releases go to PyPI as [`docunext`](https://pypi.org/project/docunext/) from GitHub Actions, using PyPI trusted
4
+ publishing: no PyPI token is stored anywhere.
5
+
6
+ ## One-time setup
7
+
8
+ 1. Create a PyPI account at pypi.org and turn on two-factor authentication.
9
+ 2. On PyPI, open **Your account** → **Publishing** → **Add a new pending publisher** → **GitHub**, and enter exactly:
10
+ - PyPI project name: `docunext`
11
+ - Owner: `a-Joe`
12
+ - Repository name: `docunext`
13
+ - Workflow name: `publish-sdk-python.yml`
14
+ - Environment name: `pypi`
15
+
16
+ A pending publisher reserves the name and lets the first release come straight from GitHub.
17
+ 3. In GitHub, open the repository's **Settings** → **Environments** → **New environment**, name it `pypi`, and
18
+ optionally add yourself as a required reviewer so each release waits for your approval.
19
+
20
+ ## Each release
21
+
22
+ 1. Update `version` in `pyproject.toml` and `__version__` in `src/docunext/_client.py` (sent in the User-Agent),
23
+ following semver: a patch for fixes, a minor for new features, a major for breaking changes.
24
+ 2. Commit and push to `master`, and wait for CI to pass.
25
+ 3. Tag the commit and push the tag:
26
+
27
+ ```bash
28
+ git tag sdk-python-v0.2.0
29
+ git push origin sdk-python-v0.2.0
30
+ ```
31
+
32
+ The **Publish Python SDK** workflow checks that the tag matches `pyproject.toml`, then type-checks, tests, builds
33
+ and publishes.
34
+
35
+ ## Working on the SDK locally
36
+
37
+ ```bash
38
+ cd packages/sdk-python
39
+ python -m venv .venv
40
+ .venv/Scripts/python -m pip install -e ".[dev]" # .venv/bin/python on macOS and Linux
41
+ .venv/Scripts/python -m pytest
42
+ .venv/Scripts/python -m mypy
43
+ ```
@@ -0,0 +1,40 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.24"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "docunext"
7
+ version = "0.1.0"
8
+ description = "Official Python client for the DocuNext document generation API."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.10"
13
+ dependencies = ["httpx>=0.27,<1", "typing_extensions>=4.7; python_version < \"3.11\""]
14
+ keywords = ["docunext", "docx", "pdf", "document generation", "templates", "api"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Intended Audience :: Developers",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3 :: Only",
21
+ "Topic :: Office/Business",
22
+ "Typing :: Typed",
23
+ ]
24
+
25
+ [project.urls]
26
+ Homepage = "https://www.docunext.app"
27
+ Documentation = "https://www.docunext.app/docs"
28
+
29
+ [project.optional-dependencies]
30
+ dev = ["pytest>=8", "mypy>=1.10"]
31
+
32
+ [tool.hatch.build.targets.wheel]
33
+ packages = ["src/docunext"]
34
+
35
+ [tool.pytest.ini_options]
36
+ testpaths = ["tests"]
37
+
38
+ [tool.mypy]
39
+ strict = true
40
+ files = ["src/docunext"]
@@ -0,0 +1,49 @@
1
+ """The official Python client for the DocuNext document generation API. See https://www.docunext.app/docs."""
2
+
3
+ from ._client import Batches, DocuNext, Documents, Templates, __version__
4
+ from ._errors import DocuNextError, DocuNextSignatureError, DocuNextTimeoutError
5
+ from ._types import (
6
+ AcceptedBatch,
7
+ AcceptedDocument,
8
+ Batch,
9
+ BatchDocument,
10
+ BatchItem,
11
+ Document,
12
+ DocumentError,
13
+ GeneratedFile,
14
+ OutputFormat,
15
+ PdfStandard,
16
+ PngOptions,
17
+ RenderData,
18
+ Template,
19
+ WebhookEvent,
20
+ )
21
+ from ._webhooks import WEBHOOK_SIGNATURE_HEADER, construct_webhook_event, verify_webhook_signature
22
+
23
+ __all__ = [
24
+ "AcceptedBatch",
25
+ "AcceptedDocument",
26
+ "Batch",
27
+ "BatchDocument",
28
+ "BatchItem",
29
+ "Batches",
30
+ "DocuNext",
31
+ "DocuNextError",
32
+ "DocuNextSignatureError",
33
+ "DocuNextTimeoutError",
34
+ "Document",
35
+ "DocumentError",
36
+ "Documents",
37
+ "GeneratedFile",
38
+ "OutputFormat",
39
+ "PdfStandard",
40
+ "PngOptions",
41
+ "RenderData",
42
+ "Template",
43
+ "Templates",
44
+ "WEBHOOK_SIGNATURE_HEADER",
45
+ "WebhookEvent",
46
+ "__version__",
47
+ "construct_webhook_event",
48
+ "verify_webhook_signature",
49
+ ]