labelproof 0.1.0__py3-none-any.whl

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/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ """HTTP client CLI for the LabelProof ZPL linter API."""
2
+
3
+ __version__ = "0.1.0"
labelproof/__main__.py ADDED
@@ -0,0 +1,4 @@
1
+ from labelproof.cli import main
2
+
3
+ if __name__ == "__main__":
4
+ raise SystemExit(main())
labelproof/cli.py ADDED
@@ -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())
labelproof/client.py ADDED
@@ -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
+ [![PyPI](https://img.shields.io/pypi/v/labelproof)](https://pypi.org/project/labelproof/)
32
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
33
+ [![labelproof.dev](https://img.shields.io/badge/site-labelproof.dev-0f172a)](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,10 @@
1
+ labelproof/__init__.py,sha256=4bwe8J6KEDLSPxxQG96kMPtZJpzeo0t4FIcUc4NFkXM,80
2
+ labelproof/__main__.py,sha256=U4hLRNAKcTflQdCMJrXgRsuu_NEDQlo2PWEsc9bxYao,89
3
+ labelproof/cli.py,sha256=5r0uHECM8aC05I1wt3cOldGplECMqzN9DBGFTQXMZbc,6646
4
+ labelproof/client.py,sha256=sLLaeKf_-me9Opr3sPfg3xxVW7JDZKVIEe7s897ngVE,2551
5
+ labelproof-0.1.0.dist-info/licenses/LICENSE,sha256=7hXr_WEqRpbC6AJ6WUfohRO9kYovxOHejD48QHI9BnI,1067
6
+ labelproof-0.1.0.dist-info/METADATA,sha256=XEJZREhtsWGZ6u16VsG1Uw86R-avYfPD0Qlb-13zss0,2832
7
+ labelproof-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
8
+ labelproof-0.1.0.dist-info/entry_points.txt,sha256=b8IrkYjHvyszgr5B0H5_Cf8AFpzXfxitrmrhLyy26r0,51
9
+ labelproof-0.1.0.dist-info/top_level.txt,sha256=QHCV-tJvm93gW9dKtUq644bXMF0mldEQ0OVU8nJN6fI,11
10
+ labelproof-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ labelproof = labelproof.cli:main
@@ -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 @@
1
+ labelproof