labelproof 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.
- labelproof-0.1.0/LICENSE +21 -0
- labelproof-0.1.0/PKG-INFO +61 -0
- labelproof-0.1.0/README.md +33 -0
- labelproof-0.1.0/pyproject.toml +49 -0
- labelproof-0.1.0/setup.cfg +4 -0
- labelproof-0.1.0/src/labelproof/__init__.py +3 -0
- labelproof-0.1.0/src/labelproof/__main__.py +4 -0
- labelproof-0.1.0/src/labelproof/cli.py +182 -0
- labelproof-0.1.0/src/labelproof/client.py +77 -0
- labelproof-0.1.0/src/labelproof.egg-info/PKG-INFO +61 -0
- labelproof-0.1.0/src/labelproof.egg-info/SOURCES.txt +14 -0
- labelproof-0.1.0/src/labelproof.egg-info/dependency_links.txt +1 -0
- labelproof-0.1.0/src/labelproof.egg-info/entry_points.txt +2 -0
- labelproof-0.1.0/src/labelproof.egg-info/requires.txt +1 -0
- labelproof-0.1.0/src/labelproof.egg-info/top_level.txt +1 -0
- labelproof-0.1.0/tests/test_client.py +64 -0
labelproof-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Wenbo Teng
|
|
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,61 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: labelproof
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: ZPL validator and ZPL linter CLI for Zebra barcode labels, via the LabelProof API (GS1-128, barcodes that will not scan).
|
|
5
|
+
Author: Wenbo Teng
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://labelproof.dev
|
|
8
|
+
Project-URL: Documentation, https://labelproof.dev/docs
|
|
9
|
+
Project-URL: Repository, https://github.com/wenboteng/labelproof-cli
|
|
10
|
+
Project-URL: Rule catalogue, https://github.com/wenboteng/labelproof-rules
|
|
11
|
+
Keywords: zpl,zpl-validator,zpl-linter,zebra,gs1-128,barcode,linter,labelproof
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
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: Topic :: Software Development :: Quality Assurance
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: requests>=2.31
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# labelproof (Python)
|
|
30
|
+
|
|
31
|
+
[](https://pypi.org/project/labelproof/)
|
|
32
|
+
[](LICENSE)
|
|
33
|
+
[](https://labelproof.dev)
|
|
34
|
+
|
|
35
|
+
Python CLI for [LabelProof](https://labelproof.dev), a **ZPL validator / ZPL linter** for Zebra barcode labels. It finds GS1-128 and Code 128 issues, barcodes that will not scan, and fields that print off the edge.
|
|
36
|
+
|
|
37
|
+
This is an HTTP client for `https://labelproof.dev/api/lint`, not a second engine. Flags match the npm package [`labelproof`](https://www.npmjs.com/package/labelproof).
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install labelproof
|
|
41
|
+
labelproof labels/ --dpi 203 --profile gs1_logistic
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`--dpi` (`203`, `300` or `600`) and `--profile` (`gs1_logistic`, `gs1_other` or `non_gs1`) are required and have no defaults.
|
|
45
|
+
|
|
46
|
+
A key is optional. Without one you are on the free tier. Set `--api-key` or `LABELPROOF_API_KEY` for a private rate-limit bucket.
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
--fail-on error|warning|info default error
|
|
50
|
+
--format text|json default text
|
|
51
|
+
--no-render skip geometry rules
|
|
52
|
+
--endpoint URL default https://labelproof.dev
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Exit codes: `0` clean, `1` findings, `2` the check could not be completed, `3` bad usage. Never treat `2` as a pass.
|
|
56
|
+
|
|
57
|
+
Labels are checked in memory and not stored. This is not an ISO/IEC 15416 print-quality grade.
|
|
58
|
+
|
|
59
|
+
Docs: https://labelproof.dev/docs · Rules: https://github.com/wenboteng/labelproof-rules · Node CLI: `npx labelproof`
|
|
60
|
+
|
|
61
|
+
MIT. Copyright (c) 2026 Wenbo Teng.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# labelproof (Python)
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/labelproof/)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
[](https://labelproof.dev)
|
|
6
|
+
|
|
7
|
+
Python CLI for [LabelProof](https://labelproof.dev), a **ZPL validator / ZPL linter** for Zebra barcode labels. It finds GS1-128 and Code 128 issues, barcodes that will not scan, and fields that print off the edge.
|
|
8
|
+
|
|
9
|
+
This is an HTTP client for `https://labelproof.dev/api/lint`, not a second engine. Flags match the npm package [`labelproof`](https://www.npmjs.com/package/labelproof).
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install labelproof
|
|
13
|
+
labelproof labels/ --dpi 203 --profile gs1_logistic
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`--dpi` (`203`, `300` or `600`) and `--profile` (`gs1_logistic`, `gs1_other` or `non_gs1`) are required and have no defaults.
|
|
17
|
+
|
|
18
|
+
A key is optional. Without one you are on the free tier. Set `--api-key` or `LABELPROOF_API_KEY` for a private rate-limit bucket.
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
--fail-on error|warning|info default error
|
|
22
|
+
--format text|json default text
|
|
23
|
+
--no-render skip geometry rules
|
|
24
|
+
--endpoint URL default https://labelproof.dev
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Exit codes: `0` clean, `1` findings, `2` the check could not be completed, `3` bad usage. Never treat `2` as a pass.
|
|
28
|
+
|
|
29
|
+
Labels are checked in memory and not stored. This is not an ISO/IEC 15416 print-quality grade.
|
|
30
|
+
|
|
31
|
+
Docs: https://labelproof.dev/docs · Rules: https://github.com/wenboteng/labelproof-rules · Node CLI: `npx labelproof`
|
|
32
|
+
|
|
33
|
+
MIT. Copyright (c) 2026 Wenbo Teng.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "labelproof"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "ZPL validator and ZPL linter CLI for Zebra barcode labels, via the LabelProof API (GS1-128, barcodes that will not scan)."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "Wenbo Teng" }]
|
|
14
|
+
keywords = [
|
|
15
|
+
"zpl",
|
|
16
|
+
"zpl-validator",
|
|
17
|
+
"zpl-linter",
|
|
18
|
+
"zebra",
|
|
19
|
+
"gs1-128",
|
|
20
|
+
"barcode",
|
|
21
|
+
"linter",
|
|
22
|
+
"labelproof",
|
|
23
|
+
]
|
|
24
|
+
classifiers = [
|
|
25
|
+
"Development Status :: 4 - Beta",
|
|
26
|
+
"Environment :: Console",
|
|
27
|
+
"Intended Audience :: Developers",
|
|
28
|
+
"Operating System :: OS Independent",
|
|
29
|
+
"Programming Language :: Python :: 3",
|
|
30
|
+
"Programming Language :: Python :: 3.9",
|
|
31
|
+
"Programming Language :: Python :: 3.10",
|
|
32
|
+
"Programming Language :: Python :: 3.11",
|
|
33
|
+
"Programming Language :: Python :: 3.12",
|
|
34
|
+
"Programming Language :: Python :: 3.13",
|
|
35
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
36
|
+
]
|
|
37
|
+
dependencies = ["requests>=2.31"]
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Homepage = "https://labelproof.dev"
|
|
41
|
+
Documentation = "https://labelproof.dev/docs"
|
|
42
|
+
Repository = "https://github.com/wenboteng/labelproof-cli"
|
|
43
|
+
"Rule catalogue" = "https://github.com/wenboteng/labelproof-rules"
|
|
44
|
+
|
|
45
|
+
[project.scripts]
|
|
46
|
+
labelproof = "labelproof.cli:main"
|
|
47
|
+
|
|
48
|
+
[tool.setuptools.packages.find]
|
|
49
|
+
where = ["src"]
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"""CLI for the LabelProof ZPL linter. Flags match the npm package `labelproof`."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import sys
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
from labelproof.client import DPIS, PROFILES, ClientError, lint
|
|
12
|
+
|
|
13
|
+
EXIT_CLEAN = 0
|
|
14
|
+
EXIT_FINDINGS = 1
|
|
15
|
+
EXIT_OPERATIONAL = 2
|
|
16
|
+
EXIT_USAGE = 3
|
|
17
|
+
FAIL_LEVELS = ("error", "warning", "info")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _fail(level: str, finding: dict) -> bool:
|
|
21
|
+
severity = finding.get("severity")
|
|
22
|
+
if severity == "error":
|
|
23
|
+
return True
|
|
24
|
+
if severity == "warning":
|
|
25
|
+
return level in ("warning", "info")
|
|
26
|
+
return level == "info"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _collect(paths: list[str]) -> list[Path]:
|
|
30
|
+
found: list[Path] = []
|
|
31
|
+
for raw in paths:
|
|
32
|
+
path = Path(raw)
|
|
33
|
+
if path.is_dir():
|
|
34
|
+
found.extend(sorted(path.rglob("*.zpl")))
|
|
35
|
+
elif any(ch in raw for ch in "*?["):
|
|
36
|
+
found.extend(sorted(Path().glob(raw)))
|
|
37
|
+
else:
|
|
38
|
+
found.append(path)
|
|
39
|
+
# unique, stable
|
|
40
|
+
seen: set[Path] = set()
|
|
41
|
+
out: list[Path] = []
|
|
42
|
+
for item in found:
|
|
43
|
+
resolved = item
|
|
44
|
+
if resolved not in seen:
|
|
45
|
+
seen.add(resolved)
|
|
46
|
+
out.append(resolved)
|
|
47
|
+
return out
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
51
|
+
parser = argparse.ArgumentParser(
|
|
52
|
+
prog="labelproof",
|
|
53
|
+
description="Check ZPL label templates before they reach a printer.",
|
|
54
|
+
)
|
|
55
|
+
parser.add_argument("paths", nargs="*", help="Files, directories or globs (*.zpl).")
|
|
56
|
+
parser.add_argument("--dpi", type=int, help="203, 300 or 600. Required. No default.")
|
|
57
|
+
parser.add_argument("--profile", help="gs1_logistic, gs1_other or non_gs1. Required. No default.")
|
|
58
|
+
parser.add_argument("--api-key", dest="api_key", help="Or set LABELPROOF_API_KEY.")
|
|
59
|
+
parser.add_argument("--fail-on", dest="fail_on", default="error", choices=FAIL_LEVELS)
|
|
60
|
+
parser.add_argument("--format", dest="fmt", default="text", choices=("text", "json"))
|
|
61
|
+
parser.add_argument("--no-render", dest="render", action="store_false", help="Skip geometry rules.")
|
|
62
|
+
parser.add_argument("--endpoint", default="https://labelproof.dev")
|
|
63
|
+
return parser
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def main(argv: list[str] | None = None) -> int:
|
|
67
|
+
parser = build_parser()
|
|
68
|
+
args = parser.parse_args(argv)
|
|
69
|
+
if args.dpi not in DPIS:
|
|
70
|
+
sys.stderr.write("error: --dpi is required and must be 203, 300 or 600.\n")
|
|
71
|
+
return EXIT_USAGE
|
|
72
|
+
if args.profile not in PROFILES:
|
|
73
|
+
sys.stderr.write(
|
|
74
|
+
"error: --profile is required and must be gs1_logistic, gs1_other or non_gs1.\n"
|
|
75
|
+
)
|
|
76
|
+
return EXIT_USAGE
|
|
77
|
+
if not args.paths:
|
|
78
|
+
sys.stderr.write("error: provide at least one file, directory or glob.\n")
|
|
79
|
+
return EXIT_USAGE
|
|
80
|
+
|
|
81
|
+
files = _collect(args.paths)
|
|
82
|
+
if not files:
|
|
83
|
+
sys.stderr.write("error: no ZPL files matched.\n")
|
|
84
|
+
return EXIT_USAGE
|
|
85
|
+
|
|
86
|
+
api_key = args.api_key or os.environ.get("LABELPROOF_API_KEY")
|
|
87
|
+
results: list[dict] = []
|
|
88
|
+
operational = False
|
|
89
|
+
for file in files:
|
|
90
|
+
try:
|
|
91
|
+
zpl = file.read_text(encoding="utf-8")
|
|
92
|
+
except OSError as exc:
|
|
93
|
+
sys.stderr.write(f"error: could not read {file}: {exc}\n")
|
|
94
|
+
operational = True
|
|
95
|
+
continue
|
|
96
|
+
try:
|
|
97
|
+
result = lint(
|
|
98
|
+
zpl,
|
|
99
|
+
args.dpi,
|
|
100
|
+
args.profile,
|
|
101
|
+
render=args.render,
|
|
102
|
+
endpoint=args.endpoint,
|
|
103
|
+
api_key=api_key,
|
|
104
|
+
)
|
|
105
|
+
except ClientError as exc:
|
|
106
|
+
sys.stderr.write(f"error: {exc}\n")
|
|
107
|
+
operational = True
|
|
108
|
+
continue
|
|
109
|
+
results.append({"file": str(file), "result": result})
|
|
110
|
+
|
|
111
|
+
if args.fmt == "json":
|
|
112
|
+
payload = []
|
|
113
|
+
for item in results:
|
|
114
|
+
result = item["result"]
|
|
115
|
+
payload.append(
|
|
116
|
+
{
|
|
117
|
+
"file": item["file"],
|
|
118
|
+
"result": {
|
|
119
|
+
"dpi": result.get("dpi"),
|
|
120
|
+
"rulesChecked": result.get("rulesChecked"),
|
|
121
|
+
"findings": [
|
|
122
|
+
{
|
|
123
|
+
"ruleId": f.get("ruleId"),
|
|
124
|
+
"severity": f.get("severity"),
|
|
125
|
+
"message": f.get("message"),
|
|
126
|
+
"fix": f.get("fix"),
|
|
127
|
+
"offset": f.get("offset"),
|
|
128
|
+
"commandText": f.get("commandText"),
|
|
129
|
+
}
|
|
130
|
+
for f in result.get("findings") or []
|
|
131
|
+
],
|
|
132
|
+
"renderUsed": result.get("renderUsed"),
|
|
133
|
+
"monthlyRenderQuotaExhausted": result.get("monthlyRenderQuotaExhausted"),
|
|
134
|
+
"tier": result.get("tier"),
|
|
135
|
+
},
|
|
136
|
+
}
|
|
137
|
+
)
|
|
138
|
+
sys.stdout.write(json.dumps(payload, indent=2) + "\n")
|
|
139
|
+
else:
|
|
140
|
+
for item in results:
|
|
141
|
+
result = item["result"]
|
|
142
|
+
findings = result.get("findings") or []
|
|
143
|
+
if not findings:
|
|
144
|
+
sys.stdout.write(
|
|
145
|
+
f"ok {item['file']} — no issues, checked against "
|
|
146
|
+
f"{result.get('rulesChecked')} rules at {result.get('dpi')} dpi\n"
|
|
147
|
+
)
|
|
148
|
+
continue
|
|
149
|
+
sys.stdout.write(f"!! {item['file']}\n")
|
|
150
|
+
for finding in findings:
|
|
151
|
+
severity = finding.get("severity")
|
|
152
|
+
label = (
|
|
153
|
+
"will fail"
|
|
154
|
+
if severity == "error"
|
|
155
|
+
else "will look wrong"
|
|
156
|
+
if severity == "warning"
|
|
157
|
+
else "works, non-standard"
|
|
158
|
+
)
|
|
159
|
+
command = finding.get("commandText") or ""
|
|
160
|
+
sys.stdout.write(
|
|
161
|
+
f" [{label}] {finding.get('ruleId')} {command} at offset {finding.get('offset')}\n"
|
|
162
|
+
)
|
|
163
|
+
sys.stdout.write(f" {finding.get('message')}\n")
|
|
164
|
+
sys.stdout.write(f" fix: {finding.get('fix')}\n")
|
|
165
|
+
sys.stdout.write("\n")
|
|
166
|
+
if any(item["result"].get("monthlyRenderQuotaExhausted") for item in results):
|
|
167
|
+
sys.stdout.write(
|
|
168
|
+
"note monthly render quota exhausted — the geometry rules were skipped. "
|
|
169
|
+
"Everything else was checked.\n"
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
if operational:
|
|
173
|
+
return EXIT_OPERATIONAL
|
|
174
|
+
for item in results:
|
|
175
|
+
for finding in item["result"].get("findings") or []:
|
|
176
|
+
if _fail(args.fail_on, finding):
|
|
177
|
+
return EXIT_FINDINGS
|
|
178
|
+
return EXIT_CLEAN
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
if __name__ == "__main__":
|
|
182
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""Thin HTTP client for POST /api/lint on labelproof.dev."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import requests
|
|
8
|
+
|
|
9
|
+
from labelproof import __version__
|
|
10
|
+
|
|
11
|
+
DEFAULT_ENDPOINT = "https://labelproof.dev"
|
|
12
|
+
USER_AGENT = f"labelproof-python/{__version__} (+https://labelproof.dev)"
|
|
13
|
+
PROFILES = ("gs1_logistic", "gs1_other", "non_gs1")
|
|
14
|
+
DPIS = (203, 300, 600)
|
|
15
|
+
TIMEOUT = 60
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ClientError(Exception):
|
|
19
|
+
def __init__(self, message: str, status: int | None = None) -> None:
|
|
20
|
+
super().__init__(message)
|
|
21
|
+
self.status = status
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def lint(
|
|
25
|
+
zpl: str,
|
|
26
|
+
dpi: int,
|
|
27
|
+
profile: str,
|
|
28
|
+
*,
|
|
29
|
+
render: bool = True,
|
|
30
|
+
endpoint: str = DEFAULT_ENDPOINT,
|
|
31
|
+
api_key: str | None = None,
|
|
32
|
+
session: requests.Session | None = None,
|
|
33
|
+
) -> dict[str, Any]:
|
|
34
|
+
if dpi not in DPIS:
|
|
35
|
+
raise ClientError("dpi is required and must be 203, 300 or 600.")
|
|
36
|
+
if profile not in PROFILES:
|
|
37
|
+
raise ClientError("profile is required and must be gs1_logistic, gs1_other or non_gs1.")
|
|
38
|
+
url = endpoint.rstrip("/") + "/api/lint"
|
|
39
|
+
headers = {
|
|
40
|
+
"Accept": "application/json",
|
|
41
|
+
"Content-Type": "application/json",
|
|
42
|
+
"User-Agent": USER_AGENT,
|
|
43
|
+
}
|
|
44
|
+
if api_key:
|
|
45
|
+
headers["X-API-Key"] = api_key
|
|
46
|
+
http = session or requests
|
|
47
|
+
try:
|
|
48
|
+
response = http.post(
|
|
49
|
+
url,
|
|
50
|
+
headers=headers,
|
|
51
|
+
json={"zpl": zpl, "dpi": dpi, "profile": profile, "render": render},
|
|
52
|
+
timeout=TIMEOUT,
|
|
53
|
+
)
|
|
54
|
+
except requests.RequestException as exc:
|
|
55
|
+
raise ClientError(f"could not reach {endpoint} — {exc}") from exc
|
|
56
|
+
if response.status_code == 429:
|
|
57
|
+
retry = response.headers.get("Retry-After")
|
|
58
|
+
wait = f" Retry-After: {retry}s." if retry else ""
|
|
59
|
+
hint = (
|
|
60
|
+
" Set LABELPROOF_API_KEY for a private bucket."
|
|
61
|
+
if not api_key
|
|
62
|
+
else " Your key has its own bucket; wait and retry."
|
|
63
|
+
)
|
|
64
|
+
raise ClientError(f"rate limit reached (HTTP 429).{wait}{hint}", 429)
|
|
65
|
+
if response.status_code == 401:
|
|
66
|
+
raise ClientError(
|
|
67
|
+
"The API key was rejected. Check LABELPROOF_API_KEY is a current LabelProof key. "
|
|
68
|
+
"Docs: https://labelproof.dev/docs",
|
|
69
|
+
401,
|
|
70
|
+
)
|
|
71
|
+
if not response.ok:
|
|
72
|
+
body = (response.text or "")[:200]
|
|
73
|
+
raise ClientError(f"the service returned {response.status_code}: {body}", response.status_code)
|
|
74
|
+
try:
|
|
75
|
+
return response.json()
|
|
76
|
+
except ValueError as exc:
|
|
77
|
+
raise ClientError("the service returned a non-JSON body") from exc
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: labelproof
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: ZPL validator and ZPL linter CLI for Zebra barcode labels, via the LabelProof API (GS1-128, barcodes that will not scan).
|
|
5
|
+
Author: Wenbo Teng
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://labelproof.dev
|
|
8
|
+
Project-URL: Documentation, https://labelproof.dev/docs
|
|
9
|
+
Project-URL: Repository, https://github.com/wenboteng/labelproof-cli
|
|
10
|
+
Project-URL: Rule catalogue, https://github.com/wenboteng/labelproof-rules
|
|
11
|
+
Keywords: zpl,zpl-validator,zpl-linter,zebra,gs1-128,barcode,linter,labelproof
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
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: Topic :: Software Development :: Quality Assurance
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: requests>=2.31
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# labelproof (Python)
|
|
30
|
+
|
|
31
|
+
[](https://pypi.org/project/labelproof/)
|
|
32
|
+
[](LICENSE)
|
|
33
|
+
[](https://labelproof.dev)
|
|
34
|
+
|
|
35
|
+
Python CLI for [LabelProof](https://labelproof.dev), a **ZPL validator / ZPL linter** for Zebra barcode labels. It finds GS1-128 and Code 128 issues, barcodes that will not scan, and fields that print off the edge.
|
|
36
|
+
|
|
37
|
+
This is an HTTP client for `https://labelproof.dev/api/lint`, not a second engine. Flags match the npm package [`labelproof`](https://www.npmjs.com/package/labelproof).
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install labelproof
|
|
41
|
+
labelproof labels/ --dpi 203 --profile gs1_logistic
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`--dpi` (`203`, `300` or `600`) and `--profile` (`gs1_logistic`, `gs1_other` or `non_gs1`) are required and have no defaults.
|
|
45
|
+
|
|
46
|
+
A key is optional. Without one you are on the free tier. Set `--api-key` or `LABELPROOF_API_KEY` for a private rate-limit bucket.
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
--fail-on error|warning|info default error
|
|
50
|
+
--format text|json default text
|
|
51
|
+
--no-render skip geometry rules
|
|
52
|
+
--endpoint URL default https://labelproof.dev
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Exit codes: `0` clean, `1` findings, `2` the check could not be completed, `3` bad usage. Never treat `2` as a pass.
|
|
56
|
+
|
|
57
|
+
Labels are checked in memory and not stored. This is not an ISO/IEC 15416 print-quality grade.
|
|
58
|
+
|
|
59
|
+
Docs: https://labelproof.dev/docs · Rules: https://github.com/wenboteng/labelproof-rules · Node CLI: `npx labelproof`
|
|
60
|
+
|
|
61
|
+
MIT. Copyright (c) 2026 Wenbo Teng.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/labelproof/__init__.py
|
|
5
|
+
src/labelproof/__main__.py
|
|
6
|
+
src/labelproof/cli.py
|
|
7
|
+
src/labelproof/client.py
|
|
8
|
+
src/labelproof.egg-info/PKG-INFO
|
|
9
|
+
src/labelproof.egg-info/SOURCES.txt
|
|
10
|
+
src/labelproof.egg-info/dependency_links.txt
|
|
11
|
+
src/labelproof.egg-info/entry_points.txt
|
|
12
|
+
src/labelproof.egg-info/requires.txt
|
|
13
|
+
src/labelproof.egg-info/top_level.txt
|
|
14
|
+
tests/test_client.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests>=2.31
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
labelproof
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import unittest
|
|
3
|
+
from unittest.mock import Mock
|
|
4
|
+
|
|
5
|
+
from labelproof.client import ClientError, lint
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class LintClientTests(unittest.TestCase):
|
|
9
|
+
def test_rejects_bad_dpi(self):
|
|
10
|
+
with self.assertRaisesRegex(ClientError, "dpi is required"):
|
|
11
|
+
lint("^XA^XZ", 96, "gs1_logistic")
|
|
12
|
+
|
|
13
|
+
def test_posts_keyless_json(self):
|
|
14
|
+
session = Mock()
|
|
15
|
+
response = Mock()
|
|
16
|
+
response.status_code = 200
|
|
17
|
+
response.ok = True
|
|
18
|
+
response.json.return_value = {
|
|
19
|
+
"dpi": 203,
|
|
20
|
+
"profile": "gs1_logistic",
|
|
21
|
+
"tier": "free",
|
|
22
|
+
"rulesChecked": 43,
|
|
23
|
+
"findings": [],
|
|
24
|
+
"renderUsed": False,
|
|
25
|
+
}
|
|
26
|
+
session.post.return_value = response
|
|
27
|
+
result = lint(
|
|
28
|
+
"^XA^XZ",
|
|
29
|
+
203,
|
|
30
|
+
"gs1_logistic",
|
|
31
|
+
render=False,
|
|
32
|
+
api_key=None,
|
|
33
|
+
session=session,
|
|
34
|
+
)
|
|
35
|
+
self.assertEqual(result["tier"], "free")
|
|
36
|
+
args, kwargs = session.post.call_args
|
|
37
|
+
self.assertTrue(str(args[0]).endswith("/api/lint"))
|
|
38
|
+
self.assertNotIn("X-API-Key", kwargs["headers"])
|
|
39
|
+
self.assertEqual(kwargs["json"]["render"], False)
|
|
40
|
+
|
|
41
|
+
def test_sends_api_key_and_maps_401(self):
|
|
42
|
+
session = Mock()
|
|
43
|
+
response = Mock()
|
|
44
|
+
response.status_code = 401
|
|
45
|
+
response.ok = False
|
|
46
|
+
response.headers = {}
|
|
47
|
+
session.post.return_value = response
|
|
48
|
+
with self.assertRaisesRegex(ClientError, "LABELPROOF_API_KEY"):
|
|
49
|
+
lint("^XA^XZ", 203, "non_gs1", api_key="lp_bad", session=session)
|
|
50
|
+
self.assertEqual(session.post.call_args.kwargs["headers"]["X-API-Key"], "lp_bad")
|
|
51
|
+
|
|
52
|
+
def test_maps_429(self):
|
|
53
|
+
session = Mock()
|
|
54
|
+
response = Mock()
|
|
55
|
+
response.status_code = 429
|
|
56
|
+
response.ok = False
|
|
57
|
+
response.headers = {"Retry-After": "20"}
|
|
58
|
+
session.post.return_value = response
|
|
59
|
+
with self.assertRaisesRegex(ClientError, "HTTP 429"):
|
|
60
|
+
lint("^XA^XZ", 203, "non_gs1", session=session)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
if __name__ == "__main__":
|
|
64
|
+
unittest.main()
|