zpl-core 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.
@@ -0,0 +1,10 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ dist/
5
+ build/
6
+ *.egg-info/
7
+ src/zpl_core/data/zpl_manual_full.txt
8
+ scratch/
9
+ out/
10
+ dist/
zpl_core-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 benyshen
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,112 @@
1
+ Metadata-Version: 2.5
2
+ Name: zpl-core
3
+ Version: 0.1.0
4
+ Summary: ZPL II engine: build, validate, render and send Zebra labels. Stdlib-only core with optional render/OCR extras.
5
+ Project-URL: Homepage, https://github.com/benyshen/zpl-core
6
+ Project-URL: Upstream, https://github.com/benyshen/zebra-printer-mcp
7
+ Author: Beny Shen
8
+ License: MIT
9
+ License-File: LICENSE
10
+ Keywords: barcode,label,link-os,mcp,printer,zebra,zpl
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Printing
15
+ Requires-Python: >=3.10
16
+ Provides-Extra: all
17
+ Requires-Dist: numpy>=1.24; extra == 'all'
18
+ Requires-Dist: onnxruntime>=1.17; extra == 'all'
19
+ Requires-Dist: opencv-python-headless>=4.9; extra == 'all'
20
+ Requires-Dist: pillow>=10.0; extra == 'all'
21
+ Requires-Dist: pyclipper>=1.3; extra == 'all'
22
+ Requires-Dist: python-barcode>=0.15; extra == 'all'
23
+ Requires-Dist: segno>=1.5; extra == 'all'
24
+ Requires-Dist: zxing-cpp>=2.2; extra == 'all'
25
+ Provides-Extra: ocr
26
+ Requires-Dist: numpy>=1.24; extra == 'ocr'
27
+ Requires-Dist: onnxruntime>=1.17; extra == 'ocr'
28
+ Requires-Dist: opencv-python-headless>=4.9; extra == 'ocr'
29
+ Requires-Dist: pyclipper>=1.3; extra == 'ocr'
30
+ Requires-Dist: zxing-cpp>=2.2; extra == 'ocr'
31
+ Provides-Extra: render
32
+ Requires-Dist: pillow>=10.0; extra == 'render'
33
+ Requires-Dist: python-barcode>=0.15; extra == 'render'
34
+ Requires-Dist: segno>=1.5; extra == 'render'
35
+ Description-Content-Type: text/markdown
36
+
37
+ # zpl-core
38
+
39
+ ZPL II 标签引擎。一份代码,三个使用者:
40
+
41
+ - **[zebra-printer-mcp](https://github.com/benyshen/zebra-printer-mcp)** —— MCP 服务器外壳(9 个工具)
42
+ - **[zebra-printer-skill](https://github.com/benyshen/zebra-printer-skill)** —— CLI / skill 外壳(10 个子命令)
43
+ - 你自己的脚本
44
+
45
+ 核心(build / validate / knowledge / transport / xlsx)**零第三方依赖**;渲染和 OCR 是可选 extras,不装不会污染环境。
46
+
47
+ ## 安装
48
+
49
+ ```bash
50
+ pip install zpl-core # 生成、校验、发送、查状态——纯 stdlib
51
+ pip install zpl-core[render] # + ZPL → PNG 离线预览(Pillow / segno / python-barcode)
52
+ pip install zpl-core[ocr] # + 照片 → ZPL(OpenCV / onnxruntime / zxing-cpp + PP-OCRv4 权重)
53
+ pip install zpl-core[all] # 全都要
54
+ ```
55
+
56
+ `[ocr]` 会让包带上约 15 MB 的 PP-OCRv4 权重(Apache-2.0),所以它不在默认安装里。
57
+
58
+ ## 五分钟
59
+
60
+ ```python
61
+ from zpl_core import builder, transport
62
+
63
+ zpl, issues = builder.build_label({
64
+ "dpi": 203, "width_mm": 60, "height_mm": 40,
65
+ "fields": [
66
+ {"type": "text", "x_mm": 3, "y_mm": 3, "height_dots": 30, "data": "五月花矿泉水"},
67
+ {"type": "barcode", "symbology": "code128", "x_mm": 3, "y_mm": 12,
68
+ "height_dots": 60, "data": "6934024512123"},
69
+ ],
70
+ })
71
+ assert not issues, issues
72
+ transport.send(zpl, host="192.168.1.50") # TCP 9100;也支持 Windows 队列 / USB / 预览文件
73
+ ```
74
+
75
+ ## 模块
76
+
77
+ | 模块 | 做什么 | 额外依赖 |
78
+ |---|---|---|
79
+ | `builder` | 标签结构体 → ZPL II;mm→dots、28 种条码、`^A@` TrueType 中文、`^GB/^GC/^FR` 图形、`^FB` 域块 | — |
80
+ | `builder.validate_zpl` | 拿手册命令目录校验原始 ZPL,返回 `{ok, issues}` | — |
81
+ | `knowledge` | 253 条命令、默认值/范围、28 种制式、27 条 SGD、13 个状态码 | — |
82
+ | `transport` | TCP 9100、Windows RAW 队列、USB、写预览文件;`~HS` 状态解析 | — |
83
+ | `xlsx_batch` | 一行一条标签,纯 `zipfile`+`xml` 读 xlsx,整批一条 ZPL 流 | — |
84
+ | `render` | ZPL → PNG,离线,用于让 agent "看一眼"版式 | `[render]` |
85
+ | `photo` | 标签照片 → ZPL(透视校正、字号推断、条码重建) | `[ocr]` |
86
+ | `ocr` | PP-OCRv4 检测/识别(onnxruntime)+ zxing-cpp 条码兜底 | `[ocr]` |
87
+ | `vision` | 纯 stdlib 的图像预处理辅助 | — |
88
+
89
+ ## 数据在哪
90
+
91
+ `zpl_core/data/` 随包安装:
92
+
93
+ - `command_catalog.txt` —— 253 条命令字,从 ZPL II Programming Guide(zpl-zbi2-pg-en-202609)的索引解析而来
94
+ - `ocr/ch_PP-OCRv4_{det,rec}_infer.onnx` + `ppocr_keys_v1.txt`
95
+
96
+ `ZPL_CORE_DATA` 可以覆盖数据目录(源码树调试用),`ZPL_CORE_OCR_MODELS` 可以单独指定模型目录。
97
+
98
+ ## 测试
99
+
100
+ ```bash
101
+ pip install -e ".[all]"
102
+ python tests/test_engine.py # 31 组 ZPL 生成断言(不需要打印机)
103
+ python tests/test_package.py # 包级不变量:数据随包、懒加载边界、253 条目录、无旧命名残留
104
+ ```
105
+
106
+ ## 边界
107
+
108
+ - 只做 ZPL II / Link-OS 打印链路:不做 RFID 编码、SNMP 监控、`^GF` 位图流、字体下载。
109
+ - `validate_zpl` 通过 **不等于** 码能扫:静区、模块宽、纠错级只有纸和扫码枪能确认。
110
+ - `photo` 识别出的文字一律当"未核对",出纸前逐字念一遍。
111
+
112
+ MIT。
@@ -0,0 +1,76 @@
1
+ # zpl-core
2
+
3
+ ZPL II 标签引擎。一份代码,三个使用者:
4
+
5
+ - **[zebra-printer-mcp](https://github.com/benyshen/zebra-printer-mcp)** —— MCP 服务器外壳(9 个工具)
6
+ - **[zebra-printer-skill](https://github.com/benyshen/zebra-printer-skill)** —— CLI / skill 外壳(10 个子命令)
7
+ - 你自己的脚本
8
+
9
+ 核心(build / validate / knowledge / transport / xlsx)**零第三方依赖**;渲染和 OCR 是可选 extras,不装不会污染环境。
10
+
11
+ ## 安装
12
+
13
+ ```bash
14
+ pip install zpl-core # 生成、校验、发送、查状态——纯 stdlib
15
+ pip install zpl-core[render] # + ZPL → PNG 离线预览(Pillow / segno / python-barcode)
16
+ pip install zpl-core[ocr] # + 照片 → ZPL(OpenCV / onnxruntime / zxing-cpp + PP-OCRv4 权重)
17
+ pip install zpl-core[all] # 全都要
18
+ ```
19
+
20
+ `[ocr]` 会让包带上约 15 MB 的 PP-OCRv4 权重(Apache-2.0),所以它不在默认安装里。
21
+
22
+ ## 五分钟
23
+
24
+ ```python
25
+ from zpl_core import builder, transport
26
+
27
+ zpl, issues = builder.build_label({
28
+ "dpi": 203, "width_mm": 60, "height_mm": 40,
29
+ "fields": [
30
+ {"type": "text", "x_mm": 3, "y_mm": 3, "height_dots": 30, "data": "五月花矿泉水"},
31
+ {"type": "barcode", "symbology": "code128", "x_mm": 3, "y_mm": 12,
32
+ "height_dots": 60, "data": "6934024512123"},
33
+ ],
34
+ })
35
+ assert not issues, issues
36
+ transport.send(zpl, host="192.168.1.50") # TCP 9100;也支持 Windows 队列 / USB / 预览文件
37
+ ```
38
+
39
+ ## 模块
40
+
41
+ | 模块 | 做什么 | 额外依赖 |
42
+ |---|---|---|
43
+ | `builder` | 标签结构体 → ZPL II;mm→dots、28 种条码、`^A@` TrueType 中文、`^GB/^GC/^FR` 图形、`^FB` 域块 | — |
44
+ | `builder.validate_zpl` | 拿手册命令目录校验原始 ZPL,返回 `{ok, issues}` | — |
45
+ | `knowledge` | 253 条命令、默认值/范围、28 种制式、27 条 SGD、13 个状态码 | — |
46
+ | `transport` | TCP 9100、Windows RAW 队列、USB、写预览文件;`~HS` 状态解析 | — |
47
+ | `xlsx_batch` | 一行一条标签,纯 `zipfile`+`xml` 读 xlsx,整批一条 ZPL 流 | — |
48
+ | `render` | ZPL → PNG,离线,用于让 agent "看一眼"版式 | `[render]` |
49
+ | `photo` | 标签照片 → ZPL(透视校正、字号推断、条码重建) | `[ocr]` |
50
+ | `ocr` | PP-OCRv4 检测/识别(onnxruntime)+ zxing-cpp 条码兜底 | `[ocr]` |
51
+ | `vision` | 纯 stdlib 的图像预处理辅助 | — |
52
+
53
+ ## 数据在哪
54
+
55
+ `zpl_core/data/` 随包安装:
56
+
57
+ - `command_catalog.txt` —— 253 条命令字,从 ZPL II Programming Guide(zpl-zbi2-pg-en-202609)的索引解析而来
58
+ - `ocr/ch_PP-OCRv4_{det,rec}_infer.onnx` + `ppocr_keys_v1.txt`
59
+
60
+ `ZPL_CORE_DATA` 可以覆盖数据目录(源码树调试用),`ZPL_CORE_OCR_MODELS` 可以单独指定模型目录。
61
+
62
+ ## 测试
63
+
64
+ ```bash
65
+ pip install -e ".[all]"
66
+ python tests/test_engine.py # 31 组 ZPL 生成断言(不需要打印机)
67
+ python tests/test_package.py # 包级不变量:数据随包、懒加载边界、253 条目录、无旧命名残留
68
+ ```
69
+
70
+ ## 边界
71
+
72
+ - 只做 ZPL II / Link-OS 打印链路:不做 RFID 编码、SNMP 监控、`^GF` 位图流、字体下载。
73
+ - `validate_zpl` 通过 **不等于** 码能扫:静区、模块宽、纠错级只有纸和扫码枪能确认。
74
+ - `photo` 识别出的文字一律当"未核对",出纸前逐字念一遍。
75
+
76
+ MIT。
@@ -0,0 +1,40 @@
1
+ [project]
2
+ name = "zpl-core"
3
+ version = "0.1.0"
4
+ description = "ZPL II engine: build, validate, render and send Zebra labels. Stdlib-only core with optional render/OCR extras."
5
+ readme = "README.md"
6
+ requires-python = ">=3.10"
7
+ license = { text = "MIT" }
8
+ authors = [{ name = "Beny Shen" }]
9
+ keywords = ["zpl", "zebra", "label", "barcode", "printer", "link-os", "mcp"]
10
+ classifiers = [
11
+ "Programming Language :: Python :: 3",
12
+ "License :: OSI Approved :: MIT License",
13
+ "Operating System :: OS Independent",
14
+ "Topic :: Printing",
15
+ ]
16
+
17
+ [project.optional-dependencies]
18
+ render = ["pillow>=10.0", "segno>=1.5", "python-barcode>=0.15"]
19
+ ocr = [
20
+ "opencv-python-headless>=4.9",
21
+ "numpy>=1.24",
22
+ "zxing-cpp>=2.2",
23
+ "onnxruntime>=1.17",
24
+ "pyclipper>=1.3",
25
+ ]
26
+ all = ["zpl-core[render,ocr]"]
27
+
28
+ [project.urls]
29
+ Homepage = "https://github.com/benyshen/zpl-core"
30
+ Upstream = "https://github.com/benyshen/zebra-printer-mcp"
31
+
32
+ [build-system]
33
+ requires = ["hatchling"]
34
+ build-backend = "hatchling.build"
35
+
36
+ [tool.hatch.build.targets.wheel]
37
+ packages = ["src/zpl_core"]
38
+
39
+ [tool.hatch.build.targets.sdist]
40
+ include = ["src/zpl_core", "tests", "README.md", "LICENSE"]
@@ -0,0 +1,44 @@
1
+ """zpl-core — the ZPL label engine behind zebra-printer-mcp and zebra-printer-skill.
2
+
3
+ One package, three consumers:
4
+
5
+ zpl_core.builder label spec -> ZPL II (mm->dots, 28 symbologies, ^A@ TrueType)
6
+ zpl_core.knowledge command catalog, defaults, barcode/status/SGD tables
7
+ zpl_core.render ZPL -> PNG preview (extra: render)
8
+ zpl_core.photo photo of a label -> ZPL (extra: ocr)
9
+ zpl_core.transport TCP 9100 / Windows RAW / USB / preview
10
+ zpl_core.xlsx_batch one label per spreadsheet row (pure stdlib)
11
+
12
+ The core (build/validate/knowledge/transport/xlsx) is stdlib-only. Heavier paths
13
+ are optional extras so a caller that just wants ZPL does not pull 15 MB of OCR
14
+ models into a build::
15
+
16
+ pip install zpl-core # build, validate, send, status
17
+ pip install zpl-core[render] # + offline PNG preview
18
+ pip install zpl-core[ocr] # + photo -> ZPL (ships PP-OCRv4 weights)
19
+ pip install zpl-core[all]
20
+ """
21
+ from __future__ import annotations
22
+
23
+ import importlib
24
+
25
+ __version__ = "0.1.0"
26
+
27
+ from . import builder, catalog, knowledge, transport, xlsx_batch # noqa: E402,F401
28
+ from .paths import DATA_DIR, data_file # noqa: E402,F401
29
+
30
+ __all__ = [
31
+ "__version__", "builder", "catalog", "knowledge", "transport", "xlsx_batch",
32
+ "render", "photo", "ocr", "vision", "DATA_DIR", "data_file",
33
+ ]
34
+
35
+ # 重模块(Pillow / cv2 / onnxruntime)按需加载,import zpl_core 不拖时间
36
+ _LAZY = {"render", "photo", "ocr", "vision"}
37
+
38
+
39
+ def __getattr__(name: str):
40
+ if name in _LAZY:
41
+ module = importlib.import_module(f".{name}", __name__)
42
+ globals()[name] = module
43
+ return module
44
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")