zpljet 1.0.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,25 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ test:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ python-version: ["3.9", "3.11", "3.13"]
17
+ steps:
18
+ - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
19
+ - uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
20
+ with:
21
+ python-version: ${{ matrix.python-version }}
22
+ - run: pip install -e ".[dev]"
23
+ - run: ruff check .
24
+ - run: mypy
25
+ - run: pytest
@@ -0,0 +1,35 @@
1
+ # Publishes GitHub Releases to PyPI.
2
+ name: Release
3
+
4
+ on:
5
+ release:
6
+ types: [published]
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ publish:
13
+ runs-on: ubuntu-latest
14
+ environment: pypi
15
+ permissions:
16
+ contents: read
17
+ id-token: write
18
+ steps:
19
+ - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
20
+ - uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
21
+ with:
22
+ python-version: "3.13"
23
+ - run: pip install -e ".[dev]" build
24
+ - run: ruff check .
25
+ - run: mypy
26
+ - run: pytest
27
+ - name: Check tag matches pyproject version
28
+ run: |
29
+ PKG_VERSION="v$(python -c "import re,pathlib;print(re.search(r'^version = \"(.+)\"$', pathlib.Path('pyproject.toml').read_text(), re.M).group(1))")"
30
+ if [ "$PKG_VERSION" != "${{ github.event.release.tag_name }}" ]; then
31
+ echo "Tag ${{ github.event.release.tag_name }} != pyproject $PKG_VERSION"
32
+ exit 1
33
+ fi
34
+ - run: python -m build
35
+ - uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
@@ -0,0 +1,13 @@
1
+ __pycache__/
2
+ *.pyc
3
+ .venv/
4
+ dist/
5
+ build/
6
+ *.egg-info/
7
+ .mypy_cache/
8
+ .ruff_cache/
9
+ .pytest_cache/
10
+ .DS_Store
11
+ *.pdf
12
+ *.png
13
+ .env
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ All notable changes to the `zpljet` Python package are documented here. The
4
+ format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
5
+ the package adheres to [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [1.0.0] - 2026-07-16
8
+
9
+ ### Added
10
+
11
+ - Public release.
zpljet-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ZPLJet
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.
zpljet-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,240 @@
1
+ Metadata-Version: 2.4
2
+ Name: zpljet
3
+ Version: 1.0.0
4
+ Summary: Official Python SDK for the ZPLJet API — fast ZPL to PDF/PNG conversion
5
+ Project-URL: Homepage, https://zpljet.com/docs
6
+ Project-URL: Documentation, https://zpljet.com/docs/sdks
7
+ Project-URL: Repository, https://github.com/zpljet/zpljet-python
8
+ Project-URL: Changelog, https://github.com/zpljet/zpljet-python/blob/main/CHANGELOG.md
9
+ Author-email: ZPLJet <support@zpljet.com>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: barcode,label,pdf,png,printing,shipping-label,zebra,zpl,zpljet
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.9
24
+ Provides-Extra: dev
25
+ Requires-Dist: build>=1; extra == 'dev'
26
+ Requires-Dist: mypy>=1.8; extra == 'dev'
27
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
28
+ Requires-Dist: pytest>=7; extra == 'dev'
29
+ Requires-Dist: ruff>=0.4; extra == 'dev'
30
+ Description-Content-Type: text/markdown
31
+
32
+ # zpljet
33
+
34
+ Official Python SDK for the [ZPLJet](https://zpljet.com) API — fast ZPL → PDF/PNG conversion.
35
+
36
+ [![PyPI version](https://img.shields.io/pypi/v/zpljet.svg)](https://pypi.org/project/zpljet/)
37
+ [![CI](https://github.com/zpljet/zpljet-python/actions/workflows/ci.yml/badge.svg)](https://github.com/zpljet/zpljet-python/actions/workflows/ci.yml)
38
+ [![license](https://img.shields.io/pypi/l/zpljet.svg)](https://github.com/zpljet/zpljet-python/blob/main/LICENSE)
39
+
40
+ - **Zero dependencies** — a single small client on top of the stdlib
41
+ - **Fully typed** (`py.typed`) — parameters, results, and every API error code
42
+ - **Reliable by default** — automatic retries with exponential backoff (honoring `Retry-After`), per-request timeouts, typed exceptions
43
+ - **Sync and async** — `ZplJet` for scripts and servers, `AsyncZplJet` for asyncio code
44
+ - Python ≥ 3.9
45
+
46
+ ## Installation
47
+
48
+ Choose one:
49
+
50
+ ```sh
51
+ pip install zpljet
52
+ uv add zpljet
53
+ poetry add zpljet
54
+ ```
55
+
56
+ ## Quickstart
57
+
58
+ Create an API key in the [dashboard](https://zpljet.com/dashboard) (keys look like `zpl_…`), then:
59
+
60
+ ```python
61
+ import os
62
+ from pathlib import Path
63
+
64
+ from zpljet import ZplJet
65
+
66
+ zpljet = ZplJet(api_key=os.environ["ZPLJET_API_KEY"])
67
+
68
+ label = zpljet.convert(zpl="^XA^FO50,50^A0N,50,50^FDHello^FS^XZ")
69
+
70
+ Path("label.pdf").write_bytes(label.data)
71
+ ```
72
+
73
+ > **Keep your API key server-side.** Anyone with the key can spend your quota.
74
+
75
+ ## Usage
76
+
77
+ ### Convert to PDF or PNG
78
+
79
+ `convert()` accepts every parameter of [`POST /v1/convert`](https://zpljet.com/docs/api-reference):
80
+
81
+ ```python
82
+ label = zpljet.convert(
83
+ zpl="^XA^FO50,50^A0N,50,50^FDHello^FS^XZ",
84
+ format="png", # "pdf" (default) | "png"
85
+ dpmm=12, # 6 | 8 (default, 203 dpi) | 12 (300 dpi) | 24 (600 dpi)
86
+ width_mm=101.6, # label width, default 4 in
87
+ height_mm=152.4, # label height, default 6 in
88
+ )
89
+
90
+ label.data # bytes — the file
91
+ label.content_type # "application/pdf" | "image/png"
92
+ label.id # conversion id (shows up in your dashboard)
93
+ ```
94
+
95
+ ### Hosted URLs (paid plans)
96
+
97
+ Pass `output="url"` to have ZPLJet host the file and return a public link
98
+ instead of the bytes. Files are retained for your account's retention window
99
+ (a dashboard setting, up to your plan's maximum).
100
+
101
+ ```python
102
+ hosted = zpljet.convert(zpl="^XA^FO50,50^A0N,50,50^FDHello^FS^XZ", output="url")
103
+
104
+ hosted.url # public URL to the PDF (works until the file is deleted)
105
+ hosted.pages # pages rendered (one per ^XA…^XZ block)
106
+ hosted.retention_days # how long the file is kept
107
+ hosted.expires_at # when the file is deleted and the URL stops working (ISO 8601, UTC)
108
+ ```
109
+
110
+ The return type narrows automatically: `output="url"` gives a `HostedLabel`,
111
+ everything else a `LabelData`.
112
+
113
+ ### Async
114
+
115
+ `AsyncZplJet` has the identical interface for asyncio code:
116
+
117
+ ```python
118
+ from zpljet import AsyncZplJet
119
+
120
+ zpljet = AsyncZplJet(api_key=os.environ["ZPLJET_API_KEY"])
121
+ label = await zpljet.convert(zpl="^XA^FO50,50^A0N,50,50^FDHello^FS^XZ")
122
+ ```
123
+
124
+ The async client runs the dependency-free transport in a worker thread. Bound
125
+ large batches with a semaphore; see
126
+ [`examples/05_async_batch.py`](https://github.com/zpljet/zpljet-python/blob/main/examples/05_async_batch.py).
127
+
128
+ ### Error handling
129
+
130
+ Every API error code maps to a dedicated exception, so you branch with
131
+ `except` — no string matching:
132
+
133
+ ```python
134
+ from zpljet import (
135
+ ZplJet,
136
+ APIConnectionError,
137
+ BadRequestError,
138
+ ConversionFailedError,
139
+ QuotaExceededError,
140
+ RateLimitError,
141
+ )
142
+
143
+ try:
144
+ label = zpljet.convert(zpl=zpl)
145
+ except BadRequestError as err:
146
+ print(f"Invalid request ({err.param}): {err.message}")
147
+ except QuotaExceededError as err:
148
+ print(f"Quota used up ({err.used}/{err.quota}), resets {err.resets_at}")
149
+ except RateLimitError as err:
150
+ print(f"Rate limited — retry after {err.retry_after}s")
151
+ except ConversionFailedError as err:
152
+ print(f"Engine rejected the ZPL (conversion {err.conversion_id})")
153
+ except APIConnectionError as err:
154
+ print(f"Network problem: {err}")
155
+ ```
156
+
157
+ | Exception | Status | `error.code` | Extra fields |
158
+ | --- | --- | --- | --- |
159
+ | `BadRequestError` | 400 | `invalid_request` | `param` |
160
+ | `AuthenticationError` | 401 | `missing_api_key` · `invalid_api_key` | — |
161
+ | `QuotaExceededError` | 402 | `quota_exceeded` | `plan`, `quota`, `used`, `resets_at` |
162
+ | `PermissionDeniedError` | 403 | `hosting_not_allowed` · `no_retention_enforced` | — |
163
+ | `PayloadTooLargeError` | 413 | `payload_too_large` | — |
164
+ | `RateLimitError` | 429 | `rate_limit_exceeded` | `retry_after`, `retry_at` |
165
+ | `ConversionFailedError` | 502 | `conversion_failed` | `conversion_id` |
166
+ | `ServiceUnavailableError` | 503 | `service_unavailable` | `retry_after` |
167
+ | `APIError` | any | anything else | `status`, `code`, `raw` |
168
+ | `APITimeoutError` | — | (an attempt timed out) | — |
169
+ | `APIConnectionError` | — | (request never got a response) | — |
170
+
171
+ All of these extend `ZplJetError`, and every HTTP error carries `status`,
172
+ `code`, `doc_url`, and the raw error payload in `raw`. Full code reference:
173
+ [zpljet.com/docs/errors](https://zpljet.com/docs/errors).
174
+
175
+ ### Retries
176
+
177
+ Rate limits, transient 5xx responses, timeouts, and network failures retry up
178
+ to twice by default. Retries use exponential backoff and honor `Retry-After`.
179
+ `conversion_failed` is never retried.
180
+
181
+ ```python
182
+ # Client-wide
183
+ zpljet = ZplJet(api_key=key, max_retries=5)
184
+
185
+ # Or per request
186
+ zpljet.convert(zpl=zpl, max_retries=0) # fail fast
187
+ ```
188
+
189
+ ### Timeouts
190
+
191
+ Each attempt has a 60-second timeout by default:
192
+
193
+ ```python
194
+ zpljet = ZplJet(api_key=key, timeout=10.0)
195
+
196
+ # Per request:
197
+ zpljet.convert(zpl=zpl, timeout=5.0)
198
+ ```
199
+
200
+ A timed-out attempt raises `APITimeoutError` (after retries).
201
+
202
+ ### Configuration
203
+
204
+ ```python
205
+ zpljet = ZplJet(
206
+ api_key="zpl_…", # required
207
+ base_url="https://api.zpljet.com", # default
208
+ timeout=60.0, # per-attempt timeout, seconds
209
+ max_retries=2, # automatic retries
210
+ transport=my_transport, # custom transport (proxies, tests)
211
+ )
212
+ ```
213
+
214
+ The default transport uses stdlib `urllib`. For connection pooling, inject any
215
+ callable matching `(url, body, headers, timeout) -> TransportResponse`.
216
+
217
+ ## Examples
218
+
219
+ Runnable scripts live in [`examples/`](https://github.com/zpljet/zpljet-python/tree/main/examples):
220
+
221
+ ```sh
222
+ ZPLJET_API_KEY=zpl_… python examples/01_convert_to_pdf.py
223
+ ```
224
+
225
+ ## Contributing & development
226
+
227
+ ```sh
228
+ python -m venv .venv && source .venv/bin/activate
229
+ pip install -e ".[dev]"
230
+
231
+ ruff check .
232
+ mypy
233
+ pytest
234
+
235
+ ZPLJET_API_KEY=zpl_… pytest tests/test_e2e.py
236
+ ```
237
+
238
+ ## License
239
+
240
+ [MIT](https://github.com/zpljet/zpljet-python/blob/main/LICENSE)
zpljet-1.0.0/README.md ADDED
@@ -0,0 +1,209 @@
1
+ # zpljet
2
+
3
+ Official Python SDK for the [ZPLJet](https://zpljet.com) API — fast ZPL → PDF/PNG conversion.
4
+
5
+ [![PyPI version](https://img.shields.io/pypi/v/zpljet.svg)](https://pypi.org/project/zpljet/)
6
+ [![CI](https://github.com/zpljet/zpljet-python/actions/workflows/ci.yml/badge.svg)](https://github.com/zpljet/zpljet-python/actions/workflows/ci.yml)
7
+ [![license](https://img.shields.io/pypi/l/zpljet.svg)](https://github.com/zpljet/zpljet-python/blob/main/LICENSE)
8
+
9
+ - **Zero dependencies** — a single small client on top of the stdlib
10
+ - **Fully typed** (`py.typed`) — parameters, results, and every API error code
11
+ - **Reliable by default** — automatic retries with exponential backoff (honoring `Retry-After`), per-request timeouts, typed exceptions
12
+ - **Sync and async** — `ZplJet` for scripts and servers, `AsyncZplJet` for asyncio code
13
+ - Python ≥ 3.9
14
+
15
+ ## Installation
16
+
17
+ Choose one:
18
+
19
+ ```sh
20
+ pip install zpljet
21
+ uv add zpljet
22
+ poetry add zpljet
23
+ ```
24
+
25
+ ## Quickstart
26
+
27
+ Create an API key in the [dashboard](https://zpljet.com/dashboard) (keys look like `zpl_…`), then:
28
+
29
+ ```python
30
+ import os
31
+ from pathlib import Path
32
+
33
+ from zpljet import ZplJet
34
+
35
+ zpljet = ZplJet(api_key=os.environ["ZPLJET_API_KEY"])
36
+
37
+ label = zpljet.convert(zpl="^XA^FO50,50^A0N,50,50^FDHello^FS^XZ")
38
+
39
+ Path("label.pdf").write_bytes(label.data)
40
+ ```
41
+
42
+ > **Keep your API key server-side.** Anyone with the key can spend your quota.
43
+
44
+ ## Usage
45
+
46
+ ### Convert to PDF or PNG
47
+
48
+ `convert()` accepts every parameter of [`POST /v1/convert`](https://zpljet.com/docs/api-reference):
49
+
50
+ ```python
51
+ label = zpljet.convert(
52
+ zpl="^XA^FO50,50^A0N,50,50^FDHello^FS^XZ",
53
+ format="png", # "pdf" (default) | "png"
54
+ dpmm=12, # 6 | 8 (default, 203 dpi) | 12 (300 dpi) | 24 (600 dpi)
55
+ width_mm=101.6, # label width, default 4 in
56
+ height_mm=152.4, # label height, default 6 in
57
+ )
58
+
59
+ label.data # bytes — the file
60
+ label.content_type # "application/pdf" | "image/png"
61
+ label.id # conversion id (shows up in your dashboard)
62
+ ```
63
+
64
+ ### Hosted URLs (paid plans)
65
+
66
+ Pass `output="url"` to have ZPLJet host the file and return a public link
67
+ instead of the bytes. Files are retained for your account's retention window
68
+ (a dashboard setting, up to your plan's maximum).
69
+
70
+ ```python
71
+ hosted = zpljet.convert(zpl="^XA^FO50,50^A0N,50,50^FDHello^FS^XZ", output="url")
72
+
73
+ hosted.url # public URL to the PDF (works until the file is deleted)
74
+ hosted.pages # pages rendered (one per ^XA…^XZ block)
75
+ hosted.retention_days # how long the file is kept
76
+ hosted.expires_at # when the file is deleted and the URL stops working (ISO 8601, UTC)
77
+ ```
78
+
79
+ The return type narrows automatically: `output="url"` gives a `HostedLabel`,
80
+ everything else a `LabelData`.
81
+
82
+ ### Async
83
+
84
+ `AsyncZplJet` has the identical interface for asyncio code:
85
+
86
+ ```python
87
+ from zpljet import AsyncZplJet
88
+
89
+ zpljet = AsyncZplJet(api_key=os.environ["ZPLJET_API_KEY"])
90
+ label = await zpljet.convert(zpl="^XA^FO50,50^A0N,50,50^FDHello^FS^XZ")
91
+ ```
92
+
93
+ The async client runs the dependency-free transport in a worker thread. Bound
94
+ large batches with a semaphore; see
95
+ [`examples/05_async_batch.py`](https://github.com/zpljet/zpljet-python/blob/main/examples/05_async_batch.py).
96
+
97
+ ### Error handling
98
+
99
+ Every API error code maps to a dedicated exception, so you branch with
100
+ `except` — no string matching:
101
+
102
+ ```python
103
+ from zpljet import (
104
+ ZplJet,
105
+ APIConnectionError,
106
+ BadRequestError,
107
+ ConversionFailedError,
108
+ QuotaExceededError,
109
+ RateLimitError,
110
+ )
111
+
112
+ try:
113
+ label = zpljet.convert(zpl=zpl)
114
+ except BadRequestError as err:
115
+ print(f"Invalid request ({err.param}): {err.message}")
116
+ except QuotaExceededError as err:
117
+ print(f"Quota used up ({err.used}/{err.quota}), resets {err.resets_at}")
118
+ except RateLimitError as err:
119
+ print(f"Rate limited — retry after {err.retry_after}s")
120
+ except ConversionFailedError as err:
121
+ print(f"Engine rejected the ZPL (conversion {err.conversion_id})")
122
+ except APIConnectionError as err:
123
+ print(f"Network problem: {err}")
124
+ ```
125
+
126
+ | Exception | Status | `error.code` | Extra fields |
127
+ | --- | --- | --- | --- |
128
+ | `BadRequestError` | 400 | `invalid_request` | `param` |
129
+ | `AuthenticationError` | 401 | `missing_api_key` · `invalid_api_key` | — |
130
+ | `QuotaExceededError` | 402 | `quota_exceeded` | `plan`, `quota`, `used`, `resets_at` |
131
+ | `PermissionDeniedError` | 403 | `hosting_not_allowed` · `no_retention_enforced` | — |
132
+ | `PayloadTooLargeError` | 413 | `payload_too_large` | — |
133
+ | `RateLimitError` | 429 | `rate_limit_exceeded` | `retry_after`, `retry_at` |
134
+ | `ConversionFailedError` | 502 | `conversion_failed` | `conversion_id` |
135
+ | `ServiceUnavailableError` | 503 | `service_unavailable` | `retry_after` |
136
+ | `APIError` | any | anything else | `status`, `code`, `raw` |
137
+ | `APITimeoutError` | — | (an attempt timed out) | — |
138
+ | `APIConnectionError` | — | (request never got a response) | — |
139
+
140
+ All of these extend `ZplJetError`, and every HTTP error carries `status`,
141
+ `code`, `doc_url`, and the raw error payload in `raw`. Full code reference:
142
+ [zpljet.com/docs/errors](https://zpljet.com/docs/errors).
143
+
144
+ ### Retries
145
+
146
+ Rate limits, transient 5xx responses, timeouts, and network failures retry up
147
+ to twice by default. Retries use exponential backoff and honor `Retry-After`.
148
+ `conversion_failed` is never retried.
149
+
150
+ ```python
151
+ # Client-wide
152
+ zpljet = ZplJet(api_key=key, max_retries=5)
153
+
154
+ # Or per request
155
+ zpljet.convert(zpl=zpl, max_retries=0) # fail fast
156
+ ```
157
+
158
+ ### Timeouts
159
+
160
+ Each attempt has a 60-second timeout by default:
161
+
162
+ ```python
163
+ zpljet = ZplJet(api_key=key, timeout=10.0)
164
+
165
+ # Per request:
166
+ zpljet.convert(zpl=zpl, timeout=5.0)
167
+ ```
168
+
169
+ A timed-out attempt raises `APITimeoutError` (after retries).
170
+
171
+ ### Configuration
172
+
173
+ ```python
174
+ zpljet = ZplJet(
175
+ api_key="zpl_…", # required
176
+ base_url="https://api.zpljet.com", # default
177
+ timeout=60.0, # per-attempt timeout, seconds
178
+ max_retries=2, # automatic retries
179
+ transport=my_transport, # custom transport (proxies, tests)
180
+ )
181
+ ```
182
+
183
+ The default transport uses stdlib `urllib`. For connection pooling, inject any
184
+ callable matching `(url, body, headers, timeout) -> TransportResponse`.
185
+
186
+ ## Examples
187
+
188
+ Runnable scripts live in [`examples/`](https://github.com/zpljet/zpljet-python/tree/main/examples):
189
+
190
+ ```sh
191
+ ZPLJET_API_KEY=zpl_… python examples/01_convert_to_pdf.py
192
+ ```
193
+
194
+ ## Contributing & development
195
+
196
+ ```sh
197
+ python -m venv .venv && source .venv/bin/activate
198
+ pip install -e ".[dev]"
199
+
200
+ ruff check .
201
+ mypy
202
+ pytest
203
+
204
+ ZPLJET_API_KEY=zpl_… pytest tests/test_e2e.py
205
+ ```
206
+
207
+ ## License
208
+
209
+ [MIT](https://github.com/zpljet/zpljet-python/blob/main/LICENSE)
@@ -0,0 +1,16 @@
1
+ """Convert ZPL to a PDF and save it locally.
2
+
3
+ Run: ZPLJET_API_KEY=zpl_… python examples/01_convert_to_pdf.py
4
+ """
5
+
6
+ import os
7
+ from pathlib import Path
8
+
9
+ from zpljet import ZplJet
10
+
11
+ zpljet = ZplJet(api_key=os.environ["ZPLJET_API_KEY"])
12
+
13
+ label = zpljet.convert(zpl="^XA^FO50,50^A0N,50,50^FDHello from ZPLJet^FS^XZ")
14
+
15
+ Path("label.pdf").write_bytes(label.data)
16
+ print(f"Saved label.pdf ({len(label.data)} bytes, conversion {label.id})")
@@ -0,0 +1,27 @@
1
+ """Render a 300 dpi PNG preview of a 4x6" shipping label.
2
+
3
+ Run: ZPLJET_API_KEY=zpl_… python examples/02_convert_to_png.py
4
+ """
5
+
6
+ import os
7
+ from pathlib import Path
8
+
9
+ from zpljet import ZplJet
10
+
11
+ zpljet = ZplJet(api_key=os.environ["ZPLJET_API_KEY"])
12
+
13
+ label = zpljet.convert(
14
+ zpl=(
15
+ "^XA"
16
+ "^FO40,40^A0N,60,60^FDACME Logistics^FS"
17
+ "^FO40,130^BY3^BCN,120,Y,N,N^FD123456789012^FS"
18
+ "^XZ"
19
+ ),
20
+ format="png",
21
+ dpmm=12, # 300 dpi
22
+ width_mm=101.6,
23
+ height_mm=152.4,
24
+ )
25
+
26
+ Path("label.png").write_bytes(label.data)
27
+ print(f"Saved label.png ({len(label.data)} bytes)")
@@ -0,0 +1,21 @@
1
+ """Host the rendered PDF and get a public URL back (paid plans).
2
+
3
+ Run: ZPLJET_API_KEY=zpl_… python examples/03_hosted_url.py
4
+ """
5
+
6
+ import os
7
+
8
+ from zpljet import PermissionDeniedError, ZplJet
9
+
10
+ zpljet = ZplJet(api_key=os.environ["ZPLJET_API_KEY"])
11
+
12
+ try:
13
+ hosted = zpljet.convert(
14
+ zpl="^XA^FO50,50^A0N,50,50^FDHosted label^FS^XZ",
15
+ output="url",
16
+ )
17
+ print(f"URL: {hosted.url}")
18
+ print(f"Pages: {hosted.pages}")
19
+ print(f"Retained: {hosted.retention_days} days (deleted {hosted.expires_at})")
20
+ except PermissionDeniedError as err:
21
+ print(f"Hosting not available on this plan: {err.message}")
@@ -0,0 +1,38 @@
1
+ """Handle every error the API can raise, with typed context fields.
2
+
3
+ Run: ZPLJET_API_KEY=zpl_… python examples/04_error_handling.py
4
+ """
5
+
6
+ import os
7
+
8
+ from zpljet import (
9
+ APIConnectionError,
10
+ AuthenticationError,
11
+ BadRequestError,
12
+ ConversionFailedError,
13
+ QuotaExceededError,
14
+ RateLimitError,
15
+ ZplJet,
16
+ )
17
+
18
+ zpljet = ZplJet(api_key=os.environ["ZPLJET_API_KEY"])
19
+
20
+ # Deliberately invalid — there is no ^XA…^XZ block.
21
+ bad_zpl = "this is not zpl"
22
+
23
+ try:
24
+ zpljet.convert(zpl=bad_zpl)
25
+ except BadRequestError as err:
26
+ print(f'Invalid request — field "{err.param}": {err.message}')
27
+ print(f"Docs: {err.doc_url}")
28
+ except AuthenticationError:
29
+ print("Bad API key — create one at https://zpljet.com/dashboard")
30
+ except QuotaExceededError as err:
31
+ print(f"Quota: {err.used}/{err.quota} used, resets {err.resets_at}")
32
+ except RateLimitError as err:
33
+ # The SDK already retried with backoff before raising this.
34
+ print(f"Still rate-limited — retry after {err.retry_after}s ({err.retry_at})")
35
+ except ConversionFailedError as err:
36
+ print(f"Engine rejected the ZPL — support id: {err.conversion_id}")
37
+ except APIConnectionError as err:
38
+ print(f"Network/timeout problem after retries: {err}")