DEVELOPERS / PYTHON / ZPL

Print ZPL Labels From Python

Two ways to print labels from Python: raw ZPL over a socket to port 9100, or the LabelInn Python SDK — print to any printer from any server, with queueing, status and templates.

FREE PLAN · NO CREDIT CARD · WINDOWS / MAC / ANDROID / WEB

THE PROBLEM

Desktop, tablet and phone syncing through the cloud to a label printer

You need Python code to put a label on a thermal printer: a shipping label when an order is paid, a product label when a batch is finished. There are two ways to do it. This page shows both, with code you can paste.

01 / PYTHON

The quick way: raw ZPL to port 9100

Zebra printers, and most printers that emulate ZPL, accept raw ZPL on TCP port 9100. If your code runs on the same network as the printer, this is all it takes:

EXAMPLEPYTHON
import socket

zpl = "^XA^FO50,50^A0N,40,40^FDHello from LabelInn^FS^XZ"

with socket.create_connection(("192.168.1.50", 9100), timeout=5) as printer:
    printer.sendall(zpl.encode("utf-8"))

02 / ZPL

Why not just open a socket?

Writing ZPL to port 9100 works on the bench. In production it leaves you with problems the printer will not solve for you:

  • Your server has to reach the printer. A cloud-hosted Python app cannot open a socket to a printer on a warehouse LAN without a VPN or port forwarding.
  • Nothing tells you it printed. Port 9100 accepts the bytes whether or not the ribbon is out or the head is open.
  • Nothing queues. If the printer is off, the job is gone.
  • One language per printer. ZPL works on Zebra; TSC wants TSPL, Toshiba wants TPCL.

LabelInn puts a small runtime next to the printer that connects out to the cloud. Your code calls one HTTPS API from anywhere; the job is queued, delivered in the printer's own language, and its status comes back.

pip install labelinn, one API key, and your Python code prints to any registered printer, anywhere. Get a key →

03 / ZEBRA

Install the SDK

EXAMPLESHELL
pip install labelinn

04 / API

Find the printer

Register the printer once in the LabelInn app on the computer it is connected to. Then list your printers to get the id:

EXAMPLEPYTHON
from labelinn import LabelInn

client = LabelInn("sk_live_...")

for printer in client.fleet.list():
    print(printer["id"], printer["name"], printer["status"])

05 / PYTHON

Print ZPL

EXAMPLEPYTHON
job = client.print.create(
    printer_id="prt_abc123",
    payload_type="zpl",
    payload_data="^XA^FO50,50^A0N,40,40^FDHello from LabelInn^FS^XZ",
)
print(job["id"], job["status"])

06 / ZPL

Print a designed label with data

Raw ZPL means your code owns the layout. With a template, the label is designed visually in LabelInn and your code sends only the data. Fields fill by name, and LabelInn converts the design to ZPL, TSPL or TPCL for whichever printer you choose.

EXAMPLEPYTHON
job = client.print.create(
    printer_id="prt_abc123",
    payload_type="template",
    design_id="dsg_shipping",
    data={"order_id": "ORD-9876", "customer": "Jane Doe", "barcode": "TR123456789"},
    copies=2,
)

07 / ZEBRA

Print many labels in one call

Batch up to 100 jobs per request. Each job is accepted or rejected on its own, so one bad row does not sink the rest.

EXAMPLEPYTHON
result = client.print.batch([
    {"printer_id": "prt_abc123", "payload_type": "template",
     "design_id": "dsg_product", "data": {"sku": sku}}
    for sku in ["A-1001", "A-1002", "A-1003"]
])
print(result["succeeded"], "of", result["total"], "accepted")

08 / API

Never print the same label twice

Retries happen: a timeout, a redeploy, a queue redelivery. Send an idempotency key and a repeated call returns the original job instead of printing again.

EXAMPLEPYTHON
job = client.print.create(
    printer_id="prt_abc123",
    payload_type="template",
    design_id="dsg_shipping",
    data={"order_id": "ORD-9876"},
    idempotency_key="order-ORD-9876-label",
)

Printing through the API is part of the Pro plan, and the free trial includes it. Keys that start with sk_test_ run against a sandbox that never prints, so you can build and test before going live. See pricing.

TESTED

What was run for this page

Environment

The snippets on this page were run on 17 October 2026 against a local mock of the API (the official SDK, installed from its package registry) and a local listener standing in for port 9100. They prove the request shape and the code compiles and runs; they do not prove a physical print.

Python 3.12 and labelinn 3.1.0 from PyPI. The SDK sent User-Agent: labelinn-python/3.1.0, Authorization: Bearer sk_test_..., POST /v1/print/jobs, and for the idempotent call the header X-Idempotency-Key: order-ORD-9876-label. The batch call posted {"jobs":[...]} to /v1/print/batch and result["succeeded"] and result["total"] read 3 and 3.

SDK factValue (checked 17 October 2026)
Packagelabelinn 3.1.0 on PyPI (pip install labelinn)
Python3.8 or newer; HTTP through requests
Other entry pointspython -m labelinn command line; LabelInnEdge for the LAN API on port 6631 with certificate pinning
Key ruleKeys must start sk_live_ or sk_test_; anything else raises ValueError before a request is made

PYTHON-SPECIFIC

Two mistakes the socket route invites

  • str instead of bytes. printer.sendall(zpl) raises TypeError: a bytes-like object is required, not 'str'. Encode: zpl.encode("utf-8"). The byte for è is c3 a8 in UTF-8 but e8 in cp1252 and 8a in cp850, so pair UTF-8 with ^CI28 in the label.
  • An unreachable printer takes the whole timeout. socket.create_connection(("10.255.255.1", 9100), timeout=2) raised TimeoutError: timed out after 2 seconds. Always pass timeout; the snippet on this page uses 5.

ERRORS

Rate limits and API errors in the SDK

EXAMPLEPYTHON
from labelinn import LabelInn
from labelinn.errors import LabelInnError, RateLimitError

client = LabelInn("sk_live_...")
try:
    job = client.print.create(printer_id="prt_abc123", payload_type="zpl", payload_data="^XA^XZ")
except RateLimitError as e:          # HTTP 429
    time.sleep(e.retry_after)         # seconds, from the API
except LabelInnError as e:            # any other API error
    print(e.status, e.code, e.message)

Tested against a mock that returned 429 BURST_RATE_LIMIT (printed RateLimitError 429 BURST_RATE_LIMIT retry_after = 7) and 400 INVALID_PRINTER (printed LabelInnError 400 INVALID_PRINTER). List calls return a list subclass that also carries .pagination and .rate_limit.

QUESTIONS / FAQ

Frequently asked questions

How do I print a ZPL label from Python?

On the same network, write the ZPL to the printer's TCP port 9100. From anywhere else, install the LabelInn SDK, register the printer once, and call print.create with payload_type "zpl" and the printer id.

Can my cloud-hosted Python app print to a printer in a warehouse?

Yes. The LabelInn runtime next to the printer connects out to LabelInn, so your server calls an HTTPS API and never needs network access to the printer itself.

Does it only work with Zebra printers?

No. Raw ZPL needs a ZPL printer, but templates are converted to the printer's own language, including TSPL for TSC and TPCL for Toshiba.

How do I avoid printing duplicates when a request is retried?

Send an idempotency key with the job. Repeating the call with the same key returns the original job instead of printing again.

Why does socket.sendall raise TypeError when I send ZPL?

Sockets send bytes, not str. Use zpl.encode("utf-8"), and start the label with ^CI28 if it contains non-ASCII text.

Which exception does the LabelInn Python SDK raise on a rate limit?

labelinn.errors.RateLimitError, a subclass of LabelInnError, with retry_after in seconds. Other API errors raise LabelInnError with status, code and message.

NEXT STEP / LABELINN

Print from Python without touching a printer driver

Get an API key, register a printer, and send your first label in minutes. · Official SDK · ZPL or visual templates · Queue, status and retries handled

Start free →