openzpl 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.
- openzpl-0.1.0/LICENSE +21 -0
- openzpl-0.1.0/PKG-INFO +79 -0
- openzpl-0.1.0/README.md +62 -0
- openzpl-0.1.0/openzpl/__init__.py +155 -0
- openzpl-0.1.0/openzpl/__main__.py +52 -0
- openzpl-0.1.0/openzpl/py.typed +0 -0
- openzpl-0.1.0/openzpl.egg-info/PKG-INFO +79 -0
- openzpl-0.1.0/openzpl.egg-info/SOURCES.txt +11 -0
- openzpl-0.1.0/openzpl.egg-info/dependency_links.txt +1 -0
- openzpl-0.1.0/openzpl.egg-info/entry_points.txt +2 -0
- openzpl-0.1.0/openzpl.egg-info/top_level.txt +1 -0
- openzpl-0.1.0/pyproject.toml +32 -0
- openzpl-0.1.0/setup.cfg +4 -0
openzpl-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 The 01 Company
|
|
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.
|
openzpl-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: openzpl
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: ZPL to PDF and PNG, PDF and image to ZPL. Client for the OpenZPL API (Labelary-compatible ZPL renderer); also reads EPL, TSPL and Datamax DPL.
|
|
5
|
+
Author: The 01 Company
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://openzpl.com/
|
|
8
|
+
Project-URL: Documentation, https://openzpl.com/docs/api/
|
|
9
|
+
Keywords: zpl,zebra,label,zpl to pdf,zpl to png,pdf to zpl,labelary,epl,tspl,barcode,thermal printer,shipping label
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Topic :: Printing
|
|
14
|
+
Requires-Python: >=3.8
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
|
|
18
|
+
# openzpl
|
|
19
|
+
|
|
20
|
+
ZPL to PDF and PNG, and PDF or image to ZPL, from Python. A small client for the [OpenZPL API](https://openzpl.com/docs/api/), a ZPL renderer compatible with Labelary's v1 API. It also reads EPL, TSPL and Datamax DPL. No dependencies beyond the standard library.
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
pip install openzpl
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## ZPL to PDF
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from openzpl import OpenZPL
|
|
30
|
+
|
|
31
|
+
client = OpenZPL() # or OpenZPL(api_key="oz_live_...")
|
|
32
|
+
pdf = client.to_pdf("^XA^FO50,50^A0N,40,40^FDHello^FS^XZ", width=4, height=6)
|
|
33
|
+
with open("label.pdf", "wb") as f:
|
|
34
|
+
f.write(pdf)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Every label in the ZPL becomes one page. `to_png(zpl, index=0)` gives one label as a PNG.
|
|
38
|
+
|
|
39
|
+
## PDF or image to ZPL
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
zpl = client.to_zpl("label.pdf", width=4, height=6) # a path or the bytes
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Each PDF page becomes one `^XA ... ^XZ` label with a `^GFA` graphic at the printer's density, ready to send to a Zebra printer. PNG, JPEG, GIF, BMP and WebP work too.
|
|
46
|
+
|
|
47
|
+
## Options
|
|
48
|
+
|
|
49
|
+
| Option | Values | Default |
|
|
50
|
+
|---|---|---|
|
|
51
|
+
| `dpmm` | 6 (152 dpi), 8 (203 dpi), 12 (300 dpi), 24 (600 dpi) | 8 |
|
|
52
|
+
| `width`, `height` | inches | 4, 6 |
|
|
53
|
+
| `index` | which label, from 0 | every label (PDF), first (PNG) |
|
|
54
|
+
| `rotation` | 0, 90, 180, 270 | 0 |
|
|
55
|
+
| `language` | `zpl`, `epl`, `tspl`, `dpl`, `auto` | zpl |
|
|
56
|
+
|
|
57
|
+
`to_zpl` also takes `threshold` (1 to 254), `dither`, `invert`, `encoding` (`z64` or `hex`) and `pages` (`"0-49"`).
|
|
58
|
+
|
|
59
|
+
## Command line
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
openzpl label.zpl label.pdf
|
|
63
|
+
openzpl label.zpl label.png --size 4x6 --dpmm 12
|
|
64
|
+
openzpl label.pdf label.zpl --size 4x6
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## API key and limits
|
|
68
|
+
|
|
69
|
+
It works without a key for a few labels a day. A free key from [openzpl.com/signup](https://openzpl.com/signup/) gives more; pass it as `api_key` or set `OPENZPL_API_KEY`. The current limits are on the [API docs](https://openzpl.com/docs/api/#limits).
|
|
70
|
+
|
|
71
|
+
## Errors
|
|
72
|
+
|
|
73
|
+
A refused request raises `OpenZPLError` with `status`, `message` and, on 429, `retry_after` in seconds.
|
|
74
|
+
|
|
75
|
+
## Moving from Labelary
|
|
76
|
+
|
|
77
|
+
The API keeps Labelary's paths and headers, so the same options apply. See [the migration guide](https://openzpl.com/migrate/labelary/).
|
|
78
|
+
|
|
79
|
+
MIT license. OpenZPL is not affiliated with Zebra Technologies or Labelary.
|
openzpl-0.1.0/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# openzpl
|
|
2
|
+
|
|
3
|
+
ZPL to PDF and PNG, and PDF or image to ZPL, from Python. A small client for the [OpenZPL API](https://openzpl.com/docs/api/), a ZPL renderer compatible with Labelary's v1 API. It also reads EPL, TSPL and Datamax DPL. No dependencies beyond the standard library.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
pip install openzpl
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## ZPL to PDF
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
from openzpl import OpenZPL
|
|
13
|
+
|
|
14
|
+
client = OpenZPL() # or OpenZPL(api_key="oz_live_...")
|
|
15
|
+
pdf = client.to_pdf("^XA^FO50,50^A0N,40,40^FDHello^FS^XZ", width=4, height=6)
|
|
16
|
+
with open("label.pdf", "wb") as f:
|
|
17
|
+
f.write(pdf)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Every label in the ZPL becomes one page. `to_png(zpl, index=0)` gives one label as a PNG.
|
|
21
|
+
|
|
22
|
+
## PDF or image to ZPL
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
zpl = client.to_zpl("label.pdf", width=4, height=6) # a path or the bytes
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Each PDF page becomes one `^XA ... ^XZ` label with a `^GFA` graphic at the printer's density, ready to send to a Zebra printer. PNG, JPEG, GIF, BMP and WebP work too.
|
|
29
|
+
|
|
30
|
+
## Options
|
|
31
|
+
|
|
32
|
+
| Option | Values | Default |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| `dpmm` | 6 (152 dpi), 8 (203 dpi), 12 (300 dpi), 24 (600 dpi) | 8 |
|
|
35
|
+
| `width`, `height` | inches | 4, 6 |
|
|
36
|
+
| `index` | which label, from 0 | every label (PDF), first (PNG) |
|
|
37
|
+
| `rotation` | 0, 90, 180, 270 | 0 |
|
|
38
|
+
| `language` | `zpl`, `epl`, `tspl`, `dpl`, `auto` | zpl |
|
|
39
|
+
|
|
40
|
+
`to_zpl` also takes `threshold` (1 to 254), `dither`, `invert`, `encoding` (`z64` or `hex`) and `pages` (`"0-49"`).
|
|
41
|
+
|
|
42
|
+
## Command line
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
openzpl label.zpl label.pdf
|
|
46
|
+
openzpl label.zpl label.png --size 4x6 --dpmm 12
|
|
47
|
+
openzpl label.pdf label.zpl --size 4x6
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## API key and limits
|
|
51
|
+
|
|
52
|
+
It works without a key for a few labels a day. A free key from [openzpl.com/signup](https://openzpl.com/signup/) gives more; pass it as `api_key` or set `OPENZPL_API_KEY`. The current limits are on the [API docs](https://openzpl.com/docs/api/#limits).
|
|
53
|
+
|
|
54
|
+
## Errors
|
|
55
|
+
|
|
56
|
+
A refused request raises `OpenZPLError` with `status`, `message` and, on 429, `retry_after` in seconds.
|
|
57
|
+
|
|
58
|
+
## Moving from Labelary
|
|
59
|
+
|
|
60
|
+
The API keeps Labelary's paths and headers, so the same options apply. See [the migration guide](https://openzpl.com/migrate/labelary/).
|
|
61
|
+
|
|
62
|
+
MIT license. OpenZPL is not affiliated with Zebra Technologies or Labelary.
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"""OpenZPL client: ZPL to PDF or PNG, PDF or image to ZPL, over the OpenZPL API.
|
|
2
|
+
|
|
3
|
+
No dependencies beyond the standard library. Docs: https://openzpl.com/docs/api/
|
|
4
|
+
|
|
5
|
+
from openzpl import OpenZPL
|
|
6
|
+
|
|
7
|
+
client = OpenZPL() # or OpenZPL(api_key="oz_live_...")
|
|
8
|
+
pdf = client.to_pdf("^XA^FO50,50^A0N,40,40^FDHello^FS^XZ")
|
|
9
|
+
open("label.pdf", "wb").write(pdf)
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import json
|
|
13
|
+
import os
|
|
14
|
+
import urllib.error
|
|
15
|
+
import urllib.parse
|
|
16
|
+
import urllib.request
|
|
17
|
+
from typing import Any, Dict, List, NamedTuple, Optional, Union
|
|
18
|
+
|
|
19
|
+
__version__ = "0.1.0"
|
|
20
|
+
__all__ = ["OpenZPL", "OpenZPLError", "Rendered", "__version__"]
|
|
21
|
+
|
|
22
|
+
DEFAULT_BASE = "https://api.openzpl.com"
|
|
23
|
+
Input = Union[str, bytes, bytearray, "os.PathLike[str]"]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class OpenZPLError(Exception):
|
|
27
|
+
"""The API refused the request. ``status`` is the HTTP status and
|
|
28
|
+
``retry_after`` the seconds to wait before trying again (429), or None."""
|
|
29
|
+
|
|
30
|
+
def __init__(self, message: str, status: int, retry_after: Optional[int] = None):
|
|
31
|
+
super().__init__(message)
|
|
32
|
+
self.message = message
|
|
33
|
+
self.status = status
|
|
34
|
+
self.retry_after = retry_after
|
|
35
|
+
|
|
36
|
+
def __str__(self) -> str:
|
|
37
|
+
return f"{self.status}: {self.message}"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class Rendered(NamedTuple):
|
|
41
|
+
data: bytes
|
|
42
|
+
#: Labels the code produces, ^PQ copies included.
|
|
43
|
+
total_count: int
|
|
44
|
+
content_type: str
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _bytes(value: Input) -> bytes:
|
|
48
|
+
if isinstance(value, (bytes, bytearray)):
|
|
49
|
+
return bytes(value)
|
|
50
|
+
if isinstance(value, str):
|
|
51
|
+
return value.encode("utf-8")
|
|
52
|
+
with open(value, "rb") as f:
|
|
53
|
+
return f.read()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _inches(n: float) -> str:
|
|
57
|
+
n = float(n)
|
|
58
|
+
if not n > 0:
|
|
59
|
+
raise ValueError("width and height are inches and must be above 0")
|
|
60
|
+
return f"{n:g}"
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class OpenZPL:
|
|
64
|
+
"""``api_key`` is optional: without one the API gives a few labels a day.
|
|
65
|
+
It falls back to the OPENZPL_API_KEY environment variable."""
|
|
66
|
+
|
|
67
|
+
def __init__(self, api_key: Optional[str] = None, base_url: str = DEFAULT_BASE, timeout: float = 30.0):
|
|
68
|
+
self.api_key = api_key or os.environ.get("OPENZPL_API_KEY", "")
|
|
69
|
+
self.base_url = base_url.rstrip("/")
|
|
70
|
+
self.timeout = timeout
|
|
71
|
+
|
|
72
|
+
def _send(self, path: str, body: bytes, headers: Dict[str, str]):
|
|
73
|
+
all_headers = {"User-Agent": f"openzpl-python/{__version__}", **headers}
|
|
74
|
+
if self.api_key:
|
|
75
|
+
all_headers["X-API-Key"] = self.api_key
|
|
76
|
+
req = urllib.request.Request(self.base_url + path, data=body, headers=all_headers, method="POST")
|
|
77
|
+
try:
|
|
78
|
+
with urllib.request.urlopen(req, timeout=self.timeout) as res:
|
|
79
|
+
return res.read(), res.headers
|
|
80
|
+
except urllib.error.HTTPError as e:
|
|
81
|
+
text = e.read().decode("utf-8", "replace")
|
|
82
|
+
if text.startswith("ERROR:"):
|
|
83
|
+
text = text[6:].strip()
|
|
84
|
+
retry = e.headers.get("Retry-After", "")
|
|
85
|
+
raise OpenZPLError(text or f"HTTP {e.code}", e.code, int(retry) if retry.isdigit() else None) from None
|
|
86
|
+
|
|
87
|
+
def render(self, code: Union[str, bytes], format: str = "pdf", *, dpmm: int = 8, width: float = 4,
|
|
88
|
+
height: float = 6, index: Optional[int] = None, rotation: int = 0,
|
|
89
|
+
quality: Optional[str] = None, language: Optional[str] = None) -> Rendered:
|
|
90
|
+
"""Render ZPL (or EPL, TSPL, Datamax DPL) to PDF or PNG. A PDF holds
|
|
91
|
+
every label unless ``index`` is given; a PNG holds one label."""
|
|
92
|
+
if format not in ("pdf", "png"):
|
|
93
|
+
raise ValueError("format is 'pdf' or 'png'")
|
|
94
|
+
path = f"/v1/printers/{int(dpmm)}dpmm/labels/{_inches(width)}x{_inches(height)}/"
|
|
95
|
+
if index is not None:
|
|
96
|
+
path += f"{int(index)}/"
|
|
97
|
+
elif format == "png":
|
|
98
|
+
path += "0/"
|
|
99
|
+
headers = {"Accept": "application/pdf" if format == "pdf" else "image/png", "Content-Type": "text/plain"}
|
|
100
|
+
if rotation:
|
|
101
|
+
headers["X-Rotation"] = str(rotation)
|
|
102
|
+
if quality:
|
|
103
|
+
headers["X-Quality"] = quality
|
|
104
|
+
if language:
|
|
105
|
+
headers["X-Language"] = language
|
|
106
|
+
body = code.encode("utf-8") if isinstance(code, str) else bytes(code)
|
|
107
|
+
data, res_headers = self._send(path, body, headers)
|
|
108
|
+
total = res_headers.get("X-Total-Count", "0")
|
|
109
|
+
return Rendered(data, int(total) if total.isdigit() else 0, res_headers.get("Content-Type", ""))
|
|
110
|
+
|
|
111
|
+
def to_pdf(self, code: Union[str, bytes], **options: Any) -> bytes:
|
|
112
|
+
"""Every label as one PDF, one page per label."""
|
|
113
|
+
return self.render(code, "pdf", **options).data
|
|
114
|
+
|
|
115
|
+
def to_png(self, code: Union[str, bytes], **options: Any) -> bytes:
|
|
116
|
+
"""One label as a PNG (``index``, from 0; the first by default)."""
|
|
117
|
+
return self.render(code, "png", **options).data
|
|
118
|
+
|
|
119
|
+
def to_zpl(self, file: Union[bytes, bytearray, "os.PathLike[str]", str], *, dpmm: Optional[int] = None,
|
|
120
|
+
width: Optional[float] = None, height: Optional[float] = None, threshold: Optional[int] = None,
|
|
121
|
+
dither: bool = False, invert: bool = False, encoding: Optional[str] = None,
|
|
122
|
+
pages: Optional[str] = None) -> str:
|
|
123
|
+
"""A PDF or an image (PNG, JPEG, GIF, BMP, WebP) to ZPL: one label per
|
|
124
|
+
page, drawn as a ^GFA graphic. ``file`` is the bytes or a path. Send
|
|
125
|
+
``width`` and ``height`` (inches) to fit the page to your label."""
|
|
126
|
+
if isinstance(file, (bytes, bytearray)):
|
|
127
|
+
body = bytes(file)
|
|
128
|
+
else:
|
|
129
|
+
with open(file, "rb") as f:
|
|
130
|
+
body = f.read()
|
|
131
|
+
query = {k: v for k, v in (("dpmm", dpmm), ("width", width), ("height", height), ("threshold", threshold),
|
|
132
|
+
("encoding", encoding), ("pages", pages)) if v is not None}
|
|
133
|
+
if dither:
|
|
134
|
+
query["dither"] = "true"
|
|
135
|
+
if invert:
|
|
136
|
+
query["invert"] = "true"
|
|
137
|
+
path = "/v1/graphics" + ("?" + urllib.parse.urlencode(query) if query else "")
|
|
138
|
+
data, _ = self._send(path, body, {"Content-Type": "application/octet-stream"})
|
|
139
|
+
return data.decode("utf-8")
|
|
140
|
+
|
|
141
|
+
def template(self, template_id: str, data: Optional[Dict[str, Any]] = None,
|
|
142
|
+
rows: Optional[List[Dict[str, Any]]] = None, format: str = "pdf") -> Union[bytes, str]:
|
|
143
|
+
"""Fill a saved design or label (``d123``, ``l45``) with your data.
|
|
144
|
+
Needs an API key. ``data`` for one label or ``rows`` for up to 50.
|
|
145
|
+
``format``: 'pdf', 'png' or 'zpl' (the filled ZPL, as text)."""
|
|
146
|
+
accept = {"pdf": "application/pdf", "png": "image/png", "zpl": "text/plain"}.get(format)
|
|
147
|
+
if not accept:
|
|
148
|
+
raise ValueError("format is 'pdf', 'png' or 'zpl'")
|
|
149
|
+
if (data is None) == (rows is None):
|
|
150
|
+
raise ValueError("pass data (one label) or rows (several), not both")
|
|
151
|
+
payload = {"data": data} if data is not None else {"rows": rows}
|
|
152
|
+
out, _ = self._send("/v1/templates/" + urllib.parse.quote(template_id, safe=""),
|
|
153
|
+
json.dumps(payload).encode("utf-8"),
|
|
154
|
+
{"Accept": accept, "Content-Type": "application/json"})
|
|
155
|
+
return out.decode("utf-8") if format == "zpl" else out
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""python -m openzpl label.zpl label.pdf (or: openzpl label.zpl label.pdf)"""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import os
|
|
5
|
+
import re
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
from . import OpenZPL, OpenZPLError
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def main(argv=None) -> int:
|
|
12
|
+
p = argparse.ArgumentParser(
|
|
13
|
+
prog="openzpl",
|
|
14
|
+
description="ZPL to PDF or PNG, and PDF or image to ZPL, by the output file's extension.",
|
|
15
|
+
epilog="Set OPENZPL_API_KEY to use your key (free at https://openzpl.com/signup/).")
|
|
16
|
+
p.add_argument("input", help="a .zpl file, or a PDF or image when the output is .zpl")
|
|
17
|
+
p.add_argument("output", help="label.pdf, label.png or label.zpl")
|
|
18
|
+
p.add_argument("--size", help="label width x height in inches, as in 4x6")
|
|
19
|
+
p.add_argument("--dpmm", type=int, choices=[6, 8, 12, 24])
|
|
20
|
+
p.add_argument("--index", type=int, help="which label, from 0")
|
|
21
|
+
a = p.parse_args(argv)
|
|
22
|
+
|
|
23
|
+
opts = {}
|
|
24
|
+
if a.size:
|
|
25
|
+
m = re.fullmatch(r"(\d+(?:\.\d+)?)x(\d+(?:\.\d+)?)", a.size)
|
|
26
|
+
if not m:
|
|
27
|
+
p.error("--size is width x height in inches, as in 4x6")
|
|
28
|
+
opts["width"], opts["height"] = float(m.group(1)), float(m.group(2))
|
|
29
|
+
if a.dpmm:
|
|
30
|
+
opts["dpmm"] = a.dpmm
|
|
31
|
+
client = OpenZPL()
|
|
32
|
+
ext = os.path.splitext(a.output)[1].lower()
|
|
33
|
+
try:
|
|
34
|
+
if ext in (".pdf", ".png"):
|
|
35
|
+
with open(a.input, "rb") as f:
|
|
36
|
+
out = client.render(f.read(), ext[1:], index=a.index, **opts)
|
|
37
|
+
with open(a.output, "wb") as f:
|
|
38
|
+
f.write(out.data)
|
|
39
|
+
print(f"{a.output}: {out.total_count} label{'' if out.total_count == 1 else 's'} in the file", file=sys.stderr)
|
|
40
|
+
else:
|
|
41
|
+
zpl = client.to_zpl(a.input, **opts)
|
|
42
|
+
with open(a.output, "w", encoding="utf-8") as f:
|
|
43
|
+
f.write(zpl)
|
|
44
|
+
print(f"{a.output}: written", file=sys.stderr)
|
|
45
|
+
except OpenZPLError as e:
|
|
46
|
+
print(f"OpenZPL {e}", file=sys.stderr)
|
|
47
|
+
return 1
|
|
48
|
+
return 0
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
if __name__ == "__main__":
|
|
52
|
+
sys.exit(main())
|
|
File without changes
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: openzpl
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: ZPL to PDF and PNG, PDF and image to ZPL. Client for the OpenZPL API (Labelary-compatible ZPL renderer); also reads EPL, TSPL and Datamax DPL.
|
|
5
|
+
Author: The 01 Company
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://openzpl.com/
|
|
8
|
+
Project-URL: Documentation, https://openzpl.com/docs/api/
|
|
9
|
+
Keywords: zpl,zebra,label,zpl to pdf,zpl to png,pdf to zpl,labelary,epl,tspl,barcode,thermal printer,shipping label
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Topic :: Printing
|
|
14
|
+
Requires-Python: >=3.8
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
|
|
18
|
+
# openzpl
|
|
19
|
+
|
|
20
|
+
ZPL to PDF and PNG, and PDF or image to ZPL, from Python. A small client for the [OpenZPL API](https://openzpl.com/docs/api/), a ZPL renderer compatible with Labelary's v1 API. It also reads EPL, TSPL and Datamax DPL. No dependencies beyond the standard library.
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
pip install openzpl
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## ZPL to PDF
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from openzpl import OpenZPL
|
|
30
|
+
|
|
31
|
+
client = OpenZPL() # or OpenZPL(api_key="oz_live_...")
|
|
32
|
+
pdf = client.to_pdf("^XA^FO50,50^A0N,40,40^FDHello^FS^XZ", width=4, height=6)
|
|
33
|
+
with open("label.pdf", "wb") as f:
|
|
34
|
+
f.write(pdf)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Every label in the ZPL becomes one page. `to_png(zpl, index=0)` gives one label as a PNG.
|
|
38
|
+
|
|
39
|
+
## PDF or image to ZPL
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
zpl = client.to_zpl("label.pdf", width=4, height=6) # a path or the bytes
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Each PDF page becomes one `^XA ... ^XZ` label with a `^GFA` graphic at the printer's density, ready to send to a Zebra printer. PNG, JPEG, GIF, BMP and WebP work too.
|
|
46
|
+
|
|
47
|
+
## Options
|
|
48
|
+
|
|
49
|
+
| Option | Values | Default |
|
|
50
|
+
|---|---|---|
|
|
51
|
+
| `dpmm` | 6 (152 dpi), 8 (203 dpi), 12 (300 dpi), 24 (600 dpi) | 8 |
|
|
52
|
+
| `width`, `height` | inches | 4, 6 |
|
|
53
|
+
| `index` | which label, from 0 | every label (PDF), first (PNG) |
|
|
54
|
+
| `rotation` | 0, 90, 180, 270 | 0 |
|
|
55
|
+
| `language` | `zpl`, `epl`, `tspl`, `dpl`, `auto` | zpl |
|
|
56
|
+
|
|
57
|
+
`to_zpl` also takes `threshold` (1 to 254), `dither`, `invert`, `encoding` (`z64` or `hex`) and `pages` (`"0-49"`).
|
|
58
|
+
|
|
59
|
+
## Command line
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
openzpl label.zpl label.pdf
|
|
63
|
+
openzpl label.zpl label.png --size 4x6 --dpmm 12
|
|
64
|
+
openzpl label.pdf label.zpl --size 4x6
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## API key and limits
|
|
68
|
+
|
|
69
|
+
It works without a key for a few labels a day. A free key from [openzpl.com/signup](https://openzpl.com/signup/) gives more; pass it as `api_key` or set `OPENZPL_API_KEY`. The current limits are on the [API docs](https://openzpl.com/docs/api/#limits).
|
|
70
|
+
|
|
71
|
+
## Errors
|
|
72
|
+
|
|
73
|
+
A refused request raises `OpenZPLError` with `status`, `message` and, on 429, `retry_after` in seconds.
|
|
74
|
+
|
|
75
|
+
## Moving from Labelary
|
|
76
|
+
|
|
77
|
+
The API keeps Labelary's paths and headers, so the same options apply. See [the migration guide](https://openzpl.com/migrate/labelary/).
|
|
78
|
+
|
|
79
|
+
MIT license. OpenZPL is not affiliated with Zebra Technologies or Labelary.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
openzpl/__init__.py
|
|
5
|
+
openzpl/__main__.py
|
|
6
|
+
openzpl/py.typed
|
|
7
|
+
openzpl.egg-info/PKG-INFO
|
|
8
|
+
openzpl.egg-info/SOURCES.txt
|
|
9
|
+
openzpl.egg-info/dependency_links.txt
|
|
10
|
+
openzpl.egg-info/entry_points.txt
|
|
11
|
+
openzpl.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
openzpl
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "openzpl"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "ZPL to PDF and PNG, PDF and image to ZPL. Client for the OpenZPL API (Labelary-compatible ZPL renderer); also reads EPL, TSPL and Datamax DPL."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "The 01 Company" }]
|
|
13
|
+
keywords = ["zpl", "zebra", "label", "zpl to pdf", "zpl to png", "pdf to zpl", "labelary", "epl", "tspl", "barcode", "thermal printer", "shipping label"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Topic :: Printing",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://openzpl.com/"
|
|
23
|
+
Documentation = "https://openzpl.com/docs/api/"
|
|
24
|
+
|
|
25
|
+
[project.scripts]
|
|
26
|
+
openzpl = "openzpl.__main__:main"
|
|
27
|
+
|
|
28
|
+
[tool.setuptools]
|
|
29
|
+
packages = ["openzpl"]
|
|
30
|
+
|
|
31
|
+
[tool.setuptools.package-data]
|
|
32
|
+
openzpl = ["py.typed"]
|
openzpl-0.1.0/setup.cfg
ADDED