DEVELOPERS / PYTHON / UPDATED 16 NOV 2026

Print ZPL From Python: Socket and SDK, Both Run

Print ZPL from Python with a socket to port 9100 or the labelinn SDK. Code was run: str vs bytes, timeouts, job status, retries without double labels.

FREE PLAN · NO CREDIT CARD · WINDOWS / MAC / ANDROID / WEB
send-9100.pyPYTHON
import socket

PRINTER = ("192.168.1.50", 9100)   # the printer's IP address and raw port

with open("label.zpl", "rb") as f:        # "rb": bytes, unchanged
    zpl = f.read()

with socket.create_connection(PRINTER, timeout=5) as s:
    s.sendall(zpl)
local listener standing in for port 9100RUN OUTPUT
listener: 49 bytes, first 3 hex 5e5841 (^XA),
last 3 hex 5e585a (^XZ), sha256 same as label.zpl
the SDK way, from anywherePYTHON
from labelinn import LabelInn

client = LabelInn("sk_live_...")
client.print.create(printer_id="prt_abc123", payload_type="zpl",
                    payload_data=open("label.zpl").read())
ON THIS PAGE Socket and SDK, both run str vs bytes, timeouts Retries without double labels Real SDK 3.1.0

SHORT ANSWER

On the printer’s network, write bytes to port 9100. From anywhere else, use the SDK.

Zebra printers read ZPL from TCP port 9100, so a socket and sendall(zpl_bytes) is enough when your script can reach the printer. When it cannot (a cloud server, a USB printer, another site) or you want a job status, pip install labelinn and call client.print.create(...): the LabelInn app next to the printer delivers the job.

  • Both snippets below were run; the output is shown.
  • The SDK examples ran against a local stand-in for the API, never the live service.
  • The two socket traps (str and the timeout) are reproduced with their real error text.
FROM YOUR PYTHON TO THE PRINTERDIAGRAM
Your Python code posts a job over HTTPS to the LabelInn cloud queue; the LabelInn app next to the printer connects out, takes the job and sends the ZPL to the Zebra

01 / DECISION

Socket or SDK: which one

The socket is the shortest path; the SDK is the one that works across networks.

Raw socket to port 9100LabelInn SDK
ReachesA network printer your script can open a TCP connection toAny registered printer, USB or network, from any server with internet
Tells you it printedNo. Port 9100 accepts bytes whether or not the ribbon is outA job status (queued to completed or failed) and webhooks
Printer offThe connection fails and the label is lostThe job waits and prints when the printer is back
Duplicates on retryYours to preventidempotency_key returns the first job instead of printing twice
Other printer brandsZPL onlySend a design with data and it is converted to ZPL, TSPL, TPCL or ESC/Label for the printer
CostNothingProduction API is on Pro ($24.90 a month); a test key and the sandbox are free

02 / SOCKET

Raw socket: the bytes, and the two traps

Open the file in binary mode so the bytes stay as they are.

send-9100.pyPYTHON
import socket

PRINTER = ("192.168.1.50", 9100)   # the printer's IP address and raw port

with open("label.zpl", "rb") as f:        # "rb": bytes, unchanged
    zpl = f.read()

with socket.create_connection(PRINTER, timeout=5) as s:
    s.sendall(zpl)

sendall takes bytes. Read the file with "rb", or encode a string with zpl.encode("utf-8") and start the label with ^CI28 so the printer reads UTF-8. The byte for è is c3 a8 in UTF-8, e8 in cp1252 and 8a in cp850, so the encoding has to match what the printer expects.

listener (stand-in for port 9100)RUN OUTPUT
$ python send-9100.py
listener: 49 bytes, first 3 hex 5e5841, last 3 hex 5e585a
sha256 of label.zpl and of what arrived:
0dbcaa09181b5083...   identical
the two traps, reproducedRUN OUTPUT
>>> s.sendall("^XA^FO50,50^A0N,40,40^FDHello from LabelInn^FS^XZ")
TypeError: a bytes-like object is required, not 'str'

>>> socket.create_connection(("10.255.255.1", 9100), timeout=2)
TimeoutError: timed out        (after 2.0 s)
What a socket cannot tell you

The listener on this page is a small TCP server, not a Zebra. Bytes arriving proves your code sent them; it does not prove a label came out. Always pass timeout: without it an unreachable printer blocks your script until the operating system gives up.

03 / SDK

The SDK: find the printer, print, wait for the result

Install with pip install labelinn (3.1.0, Python 3.8 or newer).

print-zpl.pyPYTHON
import time
from labelinn import LabelInn

client = LabelInn("sk_live_...")                    # Settings > API Keys

printer = next(p for p in client.fleet.list() if p["status"] == "online")

job = client.print.create(
    printer_id=printer["id"],
    payload_type="zpl",
    payload_data=open("label.zpl", encoding="utf-8").read(),
    idempotency_key="label-10492-1",                # same key = same job, no second label
)

while job["status"] not in ("completed", "failed", "cancelled"):
    time.sleep(2)
    job = client.print.get(job["id"])

print(job["id"], job["status"])

The printer id comes from client.fleet.list(). A 201 from the API means the job is queued, not printed, so the loop reads the job until it reaches a final state. The same key sent twice returns the same job.

what the SDK sent (stand-in API log)RUN OUTPUT
GET  /v1/fleet/printers
User-Agent: labelinn-python/3.1.0
Authorization: Bearer sk_test_...

POST /v1/print/jobs
X-Idempotency-Key: label-10492-1
{"printer_id": "prt_abc123",
 "payload_type": "zpl",
 "payload_data": "^XA^FO50,50^A0N,40,40^FDHello from LabelInn^FS^XZ"}

GET  /v1/print/jobs/job_0001   (x3)

job_0001 completed
WHAT THE LOOP WAITS FORJOB STATES
Print job states: queued, claimed, rendering, printing, completed; waitingForPrinter while the printer is unreachable; failed and cancelled are the other final states
The states come from docs/openapi.yaml. In the run above the stand-in answered queued, printing, completed.

04 / TEMPLATE

A design and data instead of ZPL, and many labels

Design the label once in LabelInn and send only the values; or batch up to 100 jobs.

template.pyPYTHON
from labelinn import LabelInn

client = LabelInn("sk_live_...")

# The design is made once in LabelInn; the code sends only the values.
job = client.print.create(
    printer_id="prt_abc123",
    payload_type="template",
    design_id="dsg_shipping",
    data={"order_id": "ORD-9876", "customer": "Maria Lopez", "barcode": "TR123456789"},
    copies=2,
    idempotency_key="order-ORD-9876-label",
)
print(job["id"], job["status"], job["copies"])

The label is drawn visually in LabelInn and bound to the field names; the app converts it to ZPL, TSPL or TPCL for whichever printer you pick. GET /v1/designs/{id}/variables lists the exact field names, so you never guess them.

batch.pyPYTHON
from labelinn import LabelInn

client = LabelInn("sk_live_...")

result = client.print.batch([
    {"printer_id": "prt_abc123", "payload_type": "zpl",
     "payload_data": f"^XA^FO50,50^A0N,40,40^FD{sku}^FS^XZ"}
    for sku in ["A-1001", "A-1002", "A-1003"]
])
print(result["succeeded"], "of", result["total"], "accepted")
outputRUN OUTPUT
job_0001 queued 2          (template.py)
3 of 3 accepted             (batch.py)

A batch is up to 100 jobs; each is accepted or refused on its own, so one bad row does not sink the rest.

05 / ERRORS

Rate limits and errors

Retry a 429 after the wait the API sends; read everything else as an error.

errors.pyPYTHON
import time
from labelinn import LabelInn
from labelinn.errors import LabelInnError, RateLimitError

client = LabelInn("sk_live_...")

def print_zpl(printer_id, zpl, key):
    for attempt in range(3):
        try:
            return client.print.create(printer_id=printer_id, payload_type="zpl",
                                       payload_data=zpl, idempotency_key=key)
        except RateLimitError as e:       # HTTP 429
            time.sleep(e.retry_after)     # seconds, sent by the API
    raise RuntimeError("still rate limited after 3 tries")

try:
    print_zpl("prt_abc123", "^XA^XZ", "label-1")
except LabelInnError as e:                # any other API error
    print(e.status, e.code, e.message)
run against the stand-in (sleep patched out)RUN OUTPUT
unknown printer
404 PRINTER_NOT_FOUND Printer prt_missing not found

rate limited (429 BURST_RATE_LIMIT, retry_after_seconds 7)
sleep 7
sleep 7
sleep 7
RuntimeError: still rate limited after 3 tries

The limit counts requests, not labels: one batch call or one data array carries many labels. Production keys get 2,000 requests a day on Pro. A failed job needs a new idempotency key (add an attempt number) or the retry returns the failed job again.

06 / SETUP

Register the printer once, with no code

The SDK talks to printers that the LabelInn app has registered.

FINDUSB OR NETWORK
LabelInn Select Printer window listing a Zebra ZTC GK420d on USB with a Connect button

STEP 1

Find the printer

Install LabelInn on the PC the Zebra is plugged into. It lists printers on USB and the network.

ADD BY IPPORT 9100
LabelInn Manual IP Entry dialog with an IP address field, port 9100 and a printer language list set to Auto-detect

STEP 2

Or add it by IP

A network printer can be added by address. 9100 is the raw port.

HISTORYREPRINT
LabelInn print history with printed, successful and failed counts and a Reprint button on a past job

STEP 3

See every job

The history lists what printed and what failed, with a Reprint button.

07 / TESTED

What was run for this page

Read this before you trust a snippet.

SnippetRun here?Result
Socket to port 9100Run against a local listener49 bytes, SHA-256 identical to the file.
str in sendall, unreachable hostRunTypeError: a bytes-like object is required, not 'str'; TimeoutError: timed out after 2.0 s.
SDK: print, poll, template, batch, errorsRun with labelinn 3.1.0 from PyPI (Python 3.12)Against a local stand-in written from the API source. User-Agent labelinn-python/3.1.0, header X-Idempotency-Key, body as shown above. Not run against the live service.
A physical ZebraNot usedNo printer was connected. Nothing here claims a label came out of a specific model.

08 / DECISION

What is free and what needs a plan

The socket is free. The SDK needs a key, and only Pro keys print.

FREE

$0

  • Design and print labels by hand on Zebra, TSC, Toshiba and Epson printers, with no label limit
  • API sandbox: a sk_test_ key, read-only, 25 calls a day (it never prints)

STARTER

$7.99 / month

  • Everything in Free
  • Excel and CSV data binding, workflows, automations
  • API sandbox: 250 calls a day (still read-only)

PRO

$24.90 / month

  • Everything in Starter
  • The production API: sk_live_ keys that print, 2,000 calls a day, 60 a minute
  • Webhooks, watched folder, database sources
Download free

A signed-in Free user can start a 14-day trial by hand from the dashboard banner or the app’s paywall (no card): it unlocks Excel and CSV binding, bulk barcodes and the production API. It does not start by itself at signup. Yearly billing is ten months for twelve ($79.90 Starter, $249.00 Pro). All plans and limits: pricing.

QUESTIONS / FAQ

Frequently asked questions

How do I print a ZPL label from Python?

On the same network, open a socket to the printer’s port 9100 and send the ZPL as bytes: socket.create_connection((host, 9100), timeout=5).sendall(zpl_bytes). From anywhere else, pip install labelinn, register the printer once in the LabelInn app, and call client.print.create(printer_id=..., payload_type="zpl", payload_data=zpl).

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

Sockets send bytes, not str. Open the file with "rb" or use zpl.encode("utf-8"), and start the label with ^CI28 if it has non-ASCII text.

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

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

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

Send idempotency_key. Repeating the call with the same key within 24 hours returns the original job instead of printing again. After a job comes back failed, use a new key, for example with an attempt counter.

Which exception does the 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.

Does it only work with Zebra printers?

Raw ZPL needs a printer that speaks ZPL. A design sent as a template is converted to the printer’s own language, including TSPL for TSC and TPCL for Toshiba.

Is there a free way to try it?

Yes: a sk_test_ key and the sandbox never print and are free to use. A signed-in Free user can start a 14-day trial by hand from the dashboard banner or the app’s paywall (no card): it unlocks Excel and CSV binding, bulk barcodes and the production API. It does not start by itself at signup.

NEXT STEP / LABELINN

Print your first label from Python

Download LabelInn, add the printer once, then call the SDK from any server. · Free plan, no card · pip install labelinn · USB, network, Bluetooth

Download free →