labelzoom-sdk 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.
- labelzoom_sdk-0.1.0/.gitignore +94 -0
- labelzoom_sdk-0.1.0/LICENSE +21 -0
- labelzoom_sdk-0.1.0/PKG-INFO +249 -0
- labelzoom_sdk-0.1.0/README.md +218 -0
- labelzoom_sdk-0.1.0/pyproject.toml +80 -0
- labelzoom_sdk-0.1.0/src/labelzoom/__init__.py +71 -0
- labelzoom_sdk-0.1.0/src/labelzoom/_version.py +3 -0
- labelzoom_sdk-0.1.0/src/labelzoom/client.py +525 -0
- labelzoom_sdk-0.1.0/src/labelzoom/errors.py +193 -0
- labelzoom_sdk-0.1.0/src/labelzoom/formats.py +115 -0
- labelzoom_sdk-0.1.0/src/labelzoom/options.py +217 -0
- labelzoom_sdk-0.1.0/src/labelzoom/py.typed +0 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Operating System Files
|
|
2
|
+
.DS_Store
|
|
3
|
+
.DS_Store?
|
|
4
|
+
._*
|
|
5
|
+
.Spotlight-V100
|
|
6
|
+
.Trashes
|
|
7
|
+
ehthumbs.db
|
|
8
|
+
Thumbs.db
|
|
9
|
+
Desktop.ini
|
|
10
|
+
|
|
11
|
+
# IDE and Editor Files
|
|
12
|
+
.vscode/
|
|
13
|
+
.idea/
|
|
14
|
+
*.swp
|
|
15
|
+
*.swo
|
|
16
|
+
*~
|
|
17
|
+
.project
|
|
18
|
+
.classpath
|
|
19
|
+
.settings/
|
|
20
|
+
|
|
21
|
+
# Python
|
|
22
|
+
__pycache__/
|
|
23
|
+
*.py[cod]
|
|
24
|
+
*$py.class
|
|
25
|
+
*.so
|
|
26
|
+
.Python
|
|
27
|
+
env/
|
|
28
|
+
venv/
|
|
29
|
+
ENV/
|
|
30
|
+
build/
|
|
31
|
+
develop-eggs/
|
|
32
|
+
dist/
|
|
33
|
+
downloads/
|
|
34
|
+
eggs/
|
|
35
|
+
.eggs/
|
|
36
|
+
lib/
|
|
37
|
+
lib64/
|
|
38
|
+
parts/
|
|
39
|
+
sdist/
|
|
40
|
+
var/
|
|
41
|
+
wheels/
|
|
42
|
+
*.egg-info/
|
|
43
|
+
.installed.cfg
|
|
44
|
+
*.egg
|
|
45
|
+
.pytest_cache/
|
|
46
|
+
.mypy_cache/
|
|
47
|
+
.ruff_cache/
|
|
48
|
+
.coverage
|
|
49
|
+
htmlcov/
|
|
50
|
+
|
|
51
|
+
# Groovy
|
|
52
|
+
*.class
|
|
53
|
+
.gradle/
|
|
54
|
+
build/
|
|
55
|
+
|
|
56
|
+
# .NET
|
|
57
|
+
[Bb]in/
|
|
58
|
+
[Oo]bj/
|
|
59
|
+
[Ll]og/
|
|
60
|
+
[Ll]ogs/
|
|
61
|
+
*.user
|
|
62
|
+
*.userosscache
|
|
63
|
+
*.suo
|
|
64
|
+
*.userprefs
|
|
65
|
+
*.sln.docstates
|
|
66
|
+
.vs/
|
|
67
|
+
project.lock.json
|
|
68
|
+
project.fragment.lock.json
|
|
69
|
+
artifacts/
|
|
70
|
+
**/Properties/launchSettings.json
|
|
71
|
+
*.dbmdl
|
|
72
|
+
*.jfm
|
|
73
|
+
*.pfx
|
|
74
|
+
*.publishsettings
|
|
75
|
+
orleans.codegen.cs
|
|
76
|
+
*.nupkg
|
|
77
|
+
*.snupkg
|
|
78
|
+
*.nuget.props
|
|
79
|
+
*.nuget.targets
|
|
80
|
+
TestResults/
|
|
81
|
+
*.VisualState.xml
|
|
82
|
+
*.binlog
|
|
83
|
+
|
|
84
|
+
# Temporary files
|
|
85
|
+
*.tmp
|
|
86
|
+
*.temp
|
|
87
|
+
*.log
|
|
88
|
+
*.bak
|
|
89
|
+
*.cache
|
|
90
|
+
|
|
91
|
+
# Environment files with secrets
|
|
92
|
+
.env
|
|
93
|
+
.env.local
|
|
94
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 LabelZoom
|
|
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,249 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: labelzoom-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python SDK for the LabelZoom API. Converts barcode labels between ZPL, EPL, TSPL, DPL, PDF, LabelZoom XML/JSON and raster images.
|
|
5
|
+
Project-URL: Homepage, https://www.labelzoom.com
|
|
6
|
+
Project-URL: Documentation, https://github.com/labelzoom/labelzoom-sdk/tree/main/python
|
|
7
|
+
Project-URL: Source, https://github.com/labelzoom/labelzoom-sdk
|
|
8
|
+
Project-URL: Issues, https://github.com/labelzoom/labelzoom-sdk/issues
|
|
9
|
+
Author-email: RJF Technology Solutions LLC <support@labelzoom.com>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: barcode,dpl,epl,label,labelzoom,pdf,tspl,zebra,zpl
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Topic :: Printing
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Requires-Dist: httpx<1,>=0.27
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: mypy>=1.11; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
29
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+

|
|
33
|
+
|
|
34
|
+
# LabelZoom Python SDK
|
|
35
|
+
|
|
36
|
+
Official Python client for the [LabelZoom API](https://api.labelzoom.com). Converts barcode
|
|
37
|
+
labels between ZPL, EPL, TSPL, DPL, PDF, LabelZoom XML/JSON, and raster images.
|
|
38
|
+
|
|
39
|
+
Python 3.10+. Fully typed (`py.typed`), sync and async clients, one dependency
|
|
40
|
+
([httpx](https://www.python-httpx.org/)).
|
|
41
|
+
|
|
42
|
+
## Install
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
pip install labelzoom-sdk
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The distribution is `labelzoom-sdk`; the import is `labelzoom`.
|
|
49
|
+
|
|
50
|
+
> **Pre-1.0.** The public API is stable in practice and covered by a shared conformance
|
|
51
|
+
> suite, but it stays on `0.x` until all seven language SDKs have validated the same
|
|
52
|
+
> contract — two contract-level corrections have already come out of that process.
|
|
53
|
+
|
|
54
|
+
## Quick start
|
|
55
|
+
|
|
56
|
+
**An API key is optional.** Without one you get the free tier — watermarked output, first label
|
|
57
|
+
only, a 1 MB request cap, and no multi-page, JSON-target, or image-to-image conversion.
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from pathlib import Path
|
|
61
|
+
from labelzoom import LabelZoomClient
|
|
62
|
+
|
|
63
|
+
with LabelZoomClient() as client: # anonymous; this works
|
|
64
|
+
result = client.convert(
|
|
65
|
+
"zpl", "png",
|
|
66
|
+
"^XA^FO20,20^A0N,28^FDHello^FS^XZ",
|
|
67
|
+
dpi=300, label_width=4, label_height=6,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
Path("label.png").write_bytes(result.content)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
`result.content` is the authoritative payload — five of the eight targets are binary.
|
|
74
|
+
`result.text` decodes it using the response charset for the textual ones.
|
|
75
|
+
|
|
76
|
+
With a key — passed explicitly, or picked up from `LABELZOOM_API_KEY`:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
client = LabelZoomClient("lz_live_...")
|
|
80
|
+
from_env = LabelZoomClient() # reads LABELZOOM_API_KEY
|
|
81
|
+
anonymous = LabelZoomClient(None) # forces anonymous, ignoring the env
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Omitting the argument and passing `None` mean different things on purpose: omitting it consults
|
|
85
|
+
the environment, and `None` (or `""`) suppresses that fallback.
|
|
86
|
+
|
|
87
|
+
Filling variable fields — **each record produces one label**:
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
result = client.convert(
|
|
91
|
+
"zpl", "pdf", template,
|
|
92
|
+
data=[{"name": "ACME Corp", "sku": "12345"},
|
|
93
|
+
{"name": "Globex", "sku": "67890"}],
|
|
94
|
+
) # a 2-page PDF
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Async
|
|
98
|
+
|
|
99
|
+
`AsyncLabelZoomClient` is a mirror, not a wrapper — same arguments, same behaviour, awaited.
|
|
100
|
+
The test suite asserts the two signatures are identical, so they cannot drift.
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
import asyncio
|
|
104
|
+
from labelzoom import AsyncLabelZoomClient
|
|
105
|
+
|
|
106
|
+
async def main() -> None:
|
|
107
|
+
async with AsyncLabelZoomClient() as client:
|
|
108
|
+
result = await client.convert("zpl", "png", zpl, dpi=300)
|
|
109
|
+
print(result.status, result.content_type, len(result.content))
|
|
110
|
+
|
|
111
|
+
asyncio.run(main())
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Formats
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
SourceFormat = Literal["zpl", "epl", "tspl", "dpl", "xml", "json",
|
|
118
|
+
"pdf", "png", "bmp", "gif", "jpeg", "jpg", "url"]
|
|
119
|
+
|
|
120
|
+
TargetFormat = Literal["zpl", "xml", "json", "pdf", "png", "bmp", "gif", "jpeg"]
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
`epl`, `tspl` and `dpl` are **source-only** on the server, and the type system says so:
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
client.convert("pdf", "epl", body)
|
|
127
|
+
# ^^^^^ error: Argument 2 has incompatible type "Literal['epl']";
|
|
128
|
+
# expected "Literal['zpl', 'xml', 'json', 'pdf', ...]"
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
A mypy error, not a runtime 404. Run mypy and you find it before you ship; the SDK also raises
|
|
132
|
+
locally rather than round-tripping to the server.
|
|
133
|
+
|
|
134
|
+
`"url"` as the source has the *server* fetch a URL you supply and convert what it finds.
|
|
135
|
+
Validate the URL first if it came from untrusted input.
|
|
136
|
+
|
|
137
|
+
## Options
|
|
138
|
+
|
|
139
|
+
Options are keyword arguments with the API's nesting flattened by underscores — `label.width`
|
|
140
|
+
becomes `label_width`, `pdf.pageNumber` becomes `pdf_page_number`.
|
|
141
|
+
|
|
142
|
+
| Keyword | Notes |
|
|
143
|
+
|---|---|
|
|
144
|
+
| `dpi` | server default 203 |
|
|
145
|
+
| `rotation` | must be a multiple of 90; rejected locally otherwise |
|
|
146
|
+
| `scaling` | percent, server default 100 |
|
|
147
|
+
| `color_mode` | `"BW"`, `"GRAYSCALE"` (default), `"COLOR"` |
|
|
148
|
+
| `darkness` | 0–100, server default 70 |
|
|
149
|
+
| `position_x`, `position_y` | pixel offset of the extracted region |
|
|
150
|
+
| `watermark` | forced on for the free tier regardless |
|
|
151
|
+
| `dialect` | e.g. `"moca"`; **paid** |
|
|
152
|
+
| `label_width`, `label_height` | **inches**, not dots |
|
|
153
|
+
| `pdf_conversion_mode` | `"IMAGE"` (default) or `"NATIVE"` |
|
|
154
|
+
| `pdf_page_number` | **0-based**; omit to convert every page |
|
|
155
|
+
| `zpl_commands_to_ignore` | e.g. `["^PQ"]` |
|
|
156
|
+
| `zpl_image_compression` | `"Z64"` (default) or `"COMPRESSED_HEX"` |
|
|
157
|
+
| `data` | one label per record |
|
|
158
|
+
| `extra` | anything not modeled yet; merged in as-is |
|
|
159
|
+
|
|
160
|
+
Only options you actually set are sent. The SDK never fills in a client-side default, so a
|
|
161
|
+
change to a server default reaches you without an SDK upgrade. That is why unset options use an
|
|
162
|
+
`UNSET` sentinel rather than `None` — `watermark=False` is a value you can deliberately send.
|
|
163
|
+
|
|
164
|
+
For building a request programmatically, `ConversionOptions` is the same field set as a frozen
|
|
165
|
+
dataclass:
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
from labelzoom import ConversionOptions
|
|
169
|
+
|
|
170
|
+
preset = ConversionOptions(dpi=300, label_width=4, label_height=6)
|
|
171
|
+
result = client.convert("zpl", "png", zpl, options=preset, rotation=90)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Keyword arguments passed alongside `options` win.
|
|
175
|
+
|
|
176
|
+
## Errors
|
|
177
|
+
|
|
178
|
+
Every non-2xx raises a typed error carrying the server's own message, the raw body, and the
|
|
179
|
+
`X-LZ-Request-Id` support handle. The body is never discarded.
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
from labelzoom import ForbiddenError, LabelZoomError
|
|
183
|
+
|
|
184
|
+
try:
|
|
185
|
+
client.convert("zpl", "json", zpl)
|
|
186
|
+
except ForbiddenError as error:
|
|
187
|
+
if error.is_paid_feature:
|
|
188
|
+
# "JSON export is a paid feature" — the most common free-tier failure.
|
|
189
|
+
print(f"{error.message} (request {error.request_id})")
|
|
190
|
+
except LabelZoomError as error:
|
|
191
|
+
print(f"{error.status}: {error.message}")
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
`BadRequestError`, `UnauthorizedError`, `ForbiddenError`, `NotFoundError`,
|
|
195
|
+
`PayloadTooLargeError`, `RateLimitedError` and `ServerError` all subclass `LabelZoomError`.
|
|
196
|
+
|
|
197
|
+
`LabelZoomValidationError` deliberately does **not** — it means the calling code is wrong, it
|
|
198
|
+
never reaches the network, and it should not be swallowed by a handler written for server
|
|
199
|
+
failures. It subclasses `ValueError`.
|
|
200
|
+
|
|
201
|
+
## Retries
|
|
202
|
+
|
|
203
|
+
429, 5xx and transport failures are retried automatically: 3 attempts, 1s/2s/4s with full
|
|
204
|
+
jitter, honouring a longer `Retry-After`. Other 4xx responses raise immediately — a malformed
|
|
205
|
+
request will not become valid on a second attempt.
|
|
206
|
+
|
|
207
|
+
```python
|
|
208
|
+
client = LabelZoomClient(max_retries=0, timeout=30.0)
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Testing your own code
|
|
212
|
+
|
|
213
|
+
The transport and the sleep function are both injectable, so retry logic can be tested without
|
|
214
|
+
spending the wall-clock time:
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
import httpx
|
|
218
|
+
from labelzoom import LabelZoomClient
|
|
219
|
+
|
|
220
|
+
slept: list[float] = []
|
|
221
|
+
client = LabelZoomClient(
|
|
222
|
+
None,
|
|
223
|
+
transport=httpx.MockTransport(lambda request: httpx.Response(200, text="^XA^XZ")),
|
|
224
|
+
use_jitter=False,
|
|
225
|
+
sleep=slept.append,
|
|
226
|
+
)
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Pass `http_client=httpx.Client(...)` instead to share a connection pool with the rest of your
|
|
230
|
+
application. The SDK will not close a client it did not create.
|
|
231
|
+
|
|
232
|
+
## Development
|
|
233
|
+
|
|
234
|
+
```sh
|
|
235
|
+
pip install -e ".[dev]"
|
|
236
|
+
pytest # offline; no key, no network
|
|
237
|
+
mypy
|
|
238
|
+
ruff check
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
The test suite runs the shared
|
|
242
|
+
[conformance fixtures](https://github.com/labelzoom/labelzoom-sdk/tree/main/conformance) that
|
|
243
|
+
every LabelZoom SDK is checked against, executes each one through **both** the sync and async
|
|
244
|
+
clients, and asserts it ran all of them. See
|
|
245
|
+
[docs/CONFORMANCE.md](https://github.com/labelzoom/labelzoom-sdk/blob/main/docs/CONFORMANCE.md).
|
|
246
|
+
|
|
247
|
+
## License
|
|
248
|
+
|
|
249
|
+
MIT — see [LICENSE](https://github.com/labelzoom/labelzoom-sdk/blob/main/LICENSE).
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# LabelZoom Python SDK
|
|
4
|
+
|
|
5
|
+
Official Python client for the [LabelZoom API](https://api.labelzoom.com). Converts barcode
|
|
6
|
+
labels between ZPL, EPL, TSPL, DPL, PDF, LabelZoom XML/JSON, and raster images.
|
|
7
|
+
|
|
8
|
+
Python 3.10+. Fully typed (`py.typed`), sync and async clients, one dependency
|
|
9
|
+
([httpx](https://www.python-httpx.org/)).
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
pip install labelzoom-sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The distribution is `labelzoom-sdk`; the import is `labelzoom`.
|
|
18
|
+
|
|
19
|
+
> **Pre-1.0.** The public API is stable in practice and covered by a shared conformance
|
|
20
|
+
> suite, but it stays on `0.x` until all seven language SDKs have validated the same
|
|
21
|
+
> contract — two contract-level corrections have already come out of that process.
|
|
22
|
+
|
|
23
|
+
## Quick start
|
|
24
|
+
|
|
25
|
+
**An API key is optional.** Without one you get the free tier — watermarked output, first label
|
|
26
|
+
only, a 1 MB request cap, and no multi-page, JSON-target, or image-to-image conversion.
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from pathlib import Path
|
|
30
|
+
from labelzoom import LabelZoomClient
|
|
31
|
+
|
|
32
|
+
with LabelZoomClient() as client: # anonymous; this works
|
|
33
|
+
result = client.convert(
|
|
34
|
+
"zpl", "png",
|
|
35
|
+
"^XA^FO20,20^A0N,28^FDHello^FS^XZ",
|
|
36
|
+
dpi=300, label_width=4, label_height=6,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
Path("label.png").write_bytes(result.content)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`result.content` is the authoritative payload — five of the eight targets are binary.
|
|
43
|
+
`result.text` decodes it using the response charset for the textual ones.
|
|
44
|
+
|
|
45
|
+
With a key — passed explicitly, or picked up from `LABELZOOM_API_KEY`:
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
client = LabelZoomClient("lz_live_...")
|
|
49
|
+
from_env = LabelZoomClient() # reads LABELZOOM_API_KEY
|
|
50
|
+
anonymous = LabelZoomClient(None) # forces anonymous, ignoring the env
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Omitting the argument and passing `None` mean different things on purpose: omitting it consults
|
|
54
|
+
the environment, and `None` (or `""`) suppresses that fallback.
|
|
55
|
+
|
|
56
|
+
Filling variable fields — **each record produces one label**:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
result = client.convert(
|
|
60
|
+
"zpl", "pdf", template,
|
|
61
|
+
data=[{"name": "ACME Corp", "sku": "12345"},
|
|
62
|
+
{"name": "Globex", "sku": "67890"}],
|
|
63
|
+
) # a 2-page PDF
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Async
|
|
67
|
+
|
|
68
|
+
`AsyncLabelZoomClient` is a mirror, not a wrapper — same arguments, same behaviour, awaited.
|
|
69
|
+
The test suite asserts the two signatures are identical, so they cannot drift.
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
import asyncio
|
|
73
|
+
from labelzoom import AsyncLabelZoomClient
|
|
74
|
+
|
|
75
|
+
async def main() -> None:
|
|
76
|
+
async with AsyncLabelZoomClient() as client:
|
|
77
|
+
result = await client.convert("zpl", "png", zpl, dpi=300)
|
|
78
|
+
print(result.status, result.content_type, len(result.content))
|
|
79
|
+
|
|
80
|
+
asyncio.run(main())
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Formats
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
SourceFormat = Literal["zpl", "epl", "tspl", "dpl", "xml", "json",
|
|
87
|
+
"pdf", "png", "bmp", "gif", "jpeg", "jpg", "url"]
|
|
88
|
+
|
|
89
|
+
TargetFormat = Literal["zpl", "xml", "json", "pdf", "png", "bmp", "gif", "jpeg"]
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`epl`, `tspl` and `dpl` are **source-only** on the server, and the type system says so:
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
client.convert("pdf", "epl", body)
|
|
96
|
+
# ^^^^^ error: Argument 2 has incompatible type "Literal['epl']";
|
|
97
|
+
# expected "Literal['zpl', 'xml', 'json', 'pdf', ...]"
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
A mypy error, not a runtime 404. Run mypy and you find it before you ship; the SDK also raises
|
|
101
|
+
locally rather than round-tripping to the server.
|
|
102
|
+
|
|
103
|
+
`"url"` as the source has the *server* fetch a URL you supply and convert what it finds.
|
|
104
|
+
Validate the URL first if it came from untrusted input.
|
|
105
|
+
|
|
106
|
+
## Options
|
|
107
|
+
|
|
108
|
+
Options are keyword arguments with the API's nesting flattened by underscores — `label.width`
|
|
109
|
+
becomes `label_width`, `pdf.pageNumber` becomes `pdf_page_number`.
|
|
110
|
+
|
|
111
|
+
| Keyword | Notes |
|
|
112
|
+
|---|---|
|
|
113
|
+
| `dpi` | server default 203 |
|
|
114
|
+
| `rotation` | must be a multiple of 90; rejected locally otherwise |
|
|
115
|
+
| `scaling` | percent, server default 100 |
|
|
116
|
+
| `color_mode` | `"BW"`, `"GRAYSCALE"` (default), `"COLOR"` |
|
|
117
|
+
| `darkness` | 0–100, server default 70 |
|
|
118
|
+
| `position_x`, `position_y` | pixel offset of the extracted region |
|
|
119
|
+
| `watermark` | forced on for the free tier regardless |
|
|
120
|
+
| `dialect` | e.g. `"moca"`; **paid** |
|
|
121
|
+
| `label_width`, `label_height` | **inches**, not dots |
|
|
122
|
+
| `pdf_conversion_mode` | `"IMAGE"` (default) or `"NATIVE"` |
|
|
123
|
+
| `pdf_page_number` | **0-based**; omit to convert every page |
|
|
124
|
+
| `zpl_commands_to_ignore` | e.g. `["^PQ"]` |
|
|
125
|
+
| `zpl_image_compression` | `"Z64"` (default) or `"COMPRESSED_HEX"` |
|
|
126
|
+
| `data` | one label per record |
|
|
127
|
+
| `extra` | anything not modeled yet; merged in as-is |
|
|
128
|
+
|
|
129
|
+
Only options you actually set are sent. The SDK never fills in a client-side default, so a
|
|
130
|
+
change to a server default reaches you without an SDK upgrade. That is why unset options use an
|
|
131
|
+
`UNSET` sentinel rather than `None` — `watermark=False` is a value you can deliberately send.
|
|
132
|
+
|
|
133
|
+
For building a request programmatically, `ConversionOptions` is the same field set as a frozen
|
|
134
|
+
dataclass:
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
from labelzoom import ConversionOptions
|
|
138
|
+
|
|
139
|
+
preset = ConversionOptions(dpi=300, label_width=4, label_height=6)
|
|
140
|
+
result = client.convert("zpl", "png", zpl, options=preset, rotation=90)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Keyword arguments passed alongside `options` win.
|
|
144
|
+
|
|
145
|
+
## Errors
|
|
146
|
+
|
|
147
|
+
Every non-2xx raises a typed error carrying the server's own message, the raw body, and the
|
|
148
|
+
`X-LZ-Request-Id` support handle. The body is never discarded.
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from labelzoom import ForbiddenError, LabelZoomError
|
|
152
|
+
|
|
153
|
+
try:
|
|
154
|
+
client.convert("zpl", "json", zpl)
|
|
155
|
+
except ForbiddenError as error:
|
|
156
|
+
if error.is_paid_feature:
|
|
157
|
+
# "JSON export is a paid feature" — the most common free-tier failure.
|
|
158
|
+
print(f"{error.message} (request {error.request_id})")
|
|
159
|
+
except LabelZoomError as error:
|
|
160
|
+
print(f"{error.status}: {error.message}")
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
`BadRequestError`, `UnauthorizedError`, `ForbiddenError`, `NotFoundError`,
|
|
164
|
+
`PayloadTooLargeError`, `RateLimitedError` and `ServerError` all subclass `LabelZoomError`.
|
|
165
|
+
|
|
166
|
+
`LabelZoomValidationError` deliberately does **not** — it means the calling code is wrong, it
|
|
167
|
+
never reaches the network, and it should not be swallowed by a handler written for server
|
|
168
|
+
failures. It subclasses `ValueError`.
|
|
169
|
+
|
|
170
|
+
## Retries
|
|
171
|
+
|
|
172
|
+
429, 5xx and transport failures are retried automatically: 3 attempts, 1s/2s/4s with full
|
|
173
|
+
jitter, honouring a longer `Retry-After`. Other 4xx responses raise immediately — a malformed
|
|
174
|
+
request will not become valid on a second attempt.
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
client = LabelZoomClient(max_retries=0, timeout=30.0)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Testing your own code
|
|
181
|
+
|
|
182
|
+
The transport and the sleep function are both injectable, so retry logic can be tested without
|
|
183
|
+
spending the wall-clock time:
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
import httpx
|
|
187
|
+
from labelzoom import LabelZoomClient
|
|
188
|
+
|
|
189
|
+
slept: list[float] = []
|
|
190
|
+
client = LabelZoomClient(
|
|
191
|
+
None,
|
|
192
|
+
transport=httpx.MockTransport(lambda request: httpx.Response(200, text="^XA^XZ")),
|
|
193
|
+
use_jitter=False,
|
|
194
|
+
sleep=slept.append,
|
|
195
|
+
)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Pass `http_client=httpx.Client(...)` instead to share a connection pool with the rest of your
|
|
199
|
+
application. The SDK will not close a client it did not create.
|
|
200
|
+
|
|
201
|
+
## Development
|
|
202
|
+
|
|
203
|
+
```sh
|
|
204
|
+
pip install -e ".[dev]"
|
|
205
|
+
pytest # offline; no key, no network
|
|
206
|
+
mypy
|
|
207
|
+
ruff check
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
The test suite runs the shared
|
|
211
|
+
[conformance fixtures](https://github.com/labelzoom/labelzoom-sdk/tree/main/conformance) that
|
|
212
|
+
every LabelZoom SDK is checked against, executes each one through **both** the sync and async
|
|
213
|
+
clients, and asserts it ran all of them. See
|
|
214
|
+
[docs/CONFORMANCE.md](https://github.com/labelzoom/labelzoom-sdk/blob/main/docs/CONFORMANCE.md).
|
|
215
|
+
|
|
216
|
+
## License
|
|
217
|
+
|
|
218
|
+
MIT — see [LICENSE](https://github.com/labelzoom/labelzoom-sdk/blob/main/LICENSE).
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "labelzoom-sdk"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Official Python SDK for the LabelZoom API. Converts barcode labels between ZPL, EPL, TSPL, DPL, PDF, LabelZoom XML/JSON and raster images."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
# A byte-identical copy of the repository LICENSE. It cannot be a parent-directory include:
|
|
12
|
+
# `python -m build` builds the wheel from the sdist, where ../LICENSE does not exist, so a
|
|
13
|
+
# source install would fail. conformance/lint.mjs asserts the copy matches the original.
|
|
14
|
+
license-files = ["LICENSE"]
|
|
15
|
+
requires-python = ">=3.10"
|
|
16
|
+
authors = [{ name = "RJF Technology Solutions LLC", email = "support@labelzoom.com" }]
|
|
17
|
+
keywords = ["labelzoom", "zpl", "epl", "tspl", "dpl", "zebra", "barcode", "label", "pdf"]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Development Status :: 4 - Beta",
|
|
20
|
+
"Intended Audience :: Developers",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Programming Language :: Python :: 3.13",
|
|
26
|
+
"Programming Language :: Python :: 3.14",
|
|
27
|
+
"Topic :: Printing",
|
|
28
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
29
|
+
"Typing :: Typed",
|
|
30
|
+
]
|
|
31
|
+
dependencies = ["httpx>=0.27,<1"]
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
Homepage = "https://www.labelzoom.com"
|
|
35
|
+
Documentation = "https://github.com/labelzoom/labelzoom-sdk/tree/main/python"
|
|
36
|
+
Source = "https://github.com/labelzoom/labelzoom-sdk"
|
|
37
|
+
Issues = "https://github.com/labelzoom/labelzoom-sdk/issues"
|
|
38
|
+
|
|
39
|
+
[project.optional-dependencies]
|
|
40
|
+
dev = ["pytest>=8", "mypy>=1.11", "ruff>=0.6"]
|
|
41
|
+
|
|
42
|
+
[tool.hatch.version]
|
|
43
|
+
path = "src/labelzoom/_version.py"
|
|
44
|
+
|
|
45
|
+
[tool.hatch.build.targets.wheel]
|
|
46
|
+
packages = ["src/labelzoom"]
|
|
47
|
+
|
|
48
|
+
[tool.hatch.build.targets.sdist]
|
|
49
|
+
# The conformance fixtures live above this directory and are not shipped, so the test suite
|
|
50
|
+
# is excluded too -- an sdist carrying a suite that cannot run is worse than one carrying none.
|
|
51
|
+
include = ["src/labelzoom", "README.md", "LICENSE", "pyproject.toml"]
|
|
52
|
+
|
|
53
|
+
[tool.pytest.ini_options]
|
|
54
|
+
testpaths = ["tests"]
|
|
55
|
+
# The completeness assertion in test_conformance.py depends on running after the parametrized
|
|
56
|
+
# cases in the same session. Do not add xdist or a shuffling plugin without reworking it.
|
|
57
|
+
addopts = "-q --strict-markers"
|
|
58
|
+
|
|
59
|
+
[tool.ruff]
|
|
60
|
+
line-length = 96
|
|
61
|
+
src = ["src", "tests"]
|
|
62
|
+
|
|
63
|
+
[tool.ruff.lint]
|
|
64
|
+
select = ["E", "F", "W", "I", "N", "UP", "B", "A", "C4", "SIM", "RUF"]
|
|
65
|
+
|
|
66
|
+
[tool.ruff.lint.per-file-ignores]
|
|
67
|
+
# The typing fixtures exist to be rejected by mypy; ruff's opinions about them are noise.
|
|
68
|
+
"tests/typecheck/*" = ["B018", "F841"]
|
|
69
|
+
|
|
70
|
+
[tool.mypy]
|
|
71
|
+
python_version = "3.10"
|
|
72
|
+
strict = true
|
|
73
|
+
warn_unused_ignores = true
|
|
74
|
+
files = ["src", "tests"]
|
|
75
|
+
|
|
76
|
+
[[tool.mypy.overrides]]
|
|
77
|
+
# The conformance runner reads untyped JSON by design: the fixtures are the schema, and
|
|
78
|
+
# annotating every `given`/`expect` shape would duplicate spec.json in Python.
|
|
79
|
+
module = "tests.test_conformance"
|
|
80
|
+
disallow_any_expr = false
|