Skip to main content

ZPL II toolchain — parse, validate, format, and print Zebra Programming Language files

Project description

zpl-toolchain

Python bindings for the zpl-toolchain — a spec-first, offline, deterministic ZPL II toolchain for parsing, validating, formatting, and printing Zebra Programming Language files.

Built with Rust for performance, exposed to Python via PyO3.

Installation

pip install zpl-toolchain

Quick Start

import json
import zpl_toolchain

# Parse ZPL — returns JSON string with AST + diagnostics
result = json.loads(zpl_toolchain.parse("^XA^FDHello^FS^XZ"))
print(f"Labels: {len(result['ast']['labels'])}")

# Validate ZPL
validation = json.loads(zpl_toolchain.validate("^XA^FDHello^FS^XZ"))
print(f"Valid: {validation['ok']}")

# Format ZPL
formatted = zpl_toolchain.format("^XA^FD Hello ^FS^XZ", "label")
print(formatted)

# Explain a diagnostic code
explanation = zpl_toolchain.explain("ZPL1201")
print(explanation)

Printing

Send ZPL directly to network printers over TCP:

import json
import zpl_toolchain

# Print ZPL to a printer (with optional validation)
result = json.loads(zpl_toolchain.print_zpl(
    "^XA^FDHello^FS^XZ",
    "192.168.1.100",   # printer address (IP or hostname:port)
))
print(f"Success: {result['success']}, Bytes sent: {result['bytes_sent']}")

# Print with profile-based validation
profile_json = open("profiles/zebra-generic-203.json").read()
result = json.loads(zpl_toolchain.print_zpl(
    "^XA^FDHello^FS^XZ",
    "192.168.1.100",
    profile_json,      # optional printer profile for validation
    True,              # validate before sending
))

# Query printer status
status_json = zpl_toolchain.query_printer_status("192.168.1.100")
status = json.loads(status_json)
print(f"Paper out: {status['paper_out']}, Paused: {status['paused']}")

API

All functions return JSON strings — use json.loads() to parse. This gives you zero-dependency interop and full access to the rich structured data.

Core Functions

Function Signature Description
parse (input: str) -> str Parse ZPL, return AST + diagnostics
parse_with_tables (input: str, tables_json: str) -> str Parse with explicit parser tables
validate (input: str, profile_json: str? = None) -> str Parse + validate (optional profile)
format (input: str, indent: str? = None) -> str Format ZPL ("none", "label", or "field")
explain (id: str) -> str? Explain a diagnostic code, or None

Print Functions

Function Signature Description
print_zpl (zpl: str, addr: str, profile: str? = None, validate: bool = True) -> str Send ZPL to a network printer over TCP
query_printer_status (addr: str) -> str Query ~HS host status from a printer

Features

  • 46 diagnostic codes covering syntax, semantics, formatting, and preflight checks
  • Printer profiles for model-specific validation (label dimensions, DPI, memory limits)
  • Deterministic output — identical input always produces identical results
  • Spec-driven — parser tables generated from ZPL II command specifications
  • Fast — native Rust performance with zero Python runtime overhead

Requirements

  • Python 3.9+
  • No additional dependencies (self-contained native extension)

Documentation

Building from Source

pip install maturin

# Build parser tables first
cargo run -p zpl_toolchain_spec_compiler -- build --spec-dir spec --out-dir generated

# Build and install (development mode)
maturin develop -m crates/python/Cargo.toml

# Or build a wheel
maturin build -m crates/python/Cargo.toml

License

Dual-licensed under MIT or Apache-2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zpl_toolchain-0.1.11-cp312-cp312-manylinux_2_34_x86_64.whl (577.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

File details

Details for the file zpl_toolchain-0.1.11-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for zpl_toolchain-0.1.11-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 eeee32d8da30cd96d68ec6edca36d42e1d9c7f90f845469cece5390f6812444e
MD5 6356a29e06a6eb900f251018e934359f
BLAKE2b-256 a8c88d25bfb1c69913211e2f27c2cf5f392c038c844dd709db110c8389c43a28

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page