Sign In
Products
ZPL ViewerBarcode GeneratorImage → ZPLZPL cheat sheetLabel DesignerTemplate Gallery
Developers
API QuickstartAPI ReferenceMCP ServerBulk GenerationWebhooksSDKs & ExamplesLimitsDirectPrint agent NewGitHub ActionVS Code extensionOn-Premise
Solutions
Logistics & ShippingE-CommerceERP & WMSManufacturingRetailHealthcare & LaboratoryAll solutions
Tools
ZPL Diagnostics HubZPL DebuggerSize & DPI AnalyzerDPI ConverterBarcode fit calculatorShipping Label AnalyzerFont InspectorOrientation DebuggerCalibration AssistantPrinter Compatibility CheckerBarcode Readability CheckerPrinter Language DetectorThermal Printer Test PackZPL ToolsEPL ToolsTSPL ToolsCPCL ToolsPrinter Language ConverterAll ToolsGuidesPricing
Language
EnglishTürkçeDeutsch
Home›Developers›Code Examples

Code Examples

Examples of using the Labelixa API with cURL, Python, C#, Java, Node.js and PHP: ZPL rendering and barcode generation.

Official Python SDK

A thin official client instead of raw HTTP: quota errors are a distinct class (QuotaExceeded, carrying retry_after), and error messages come from the server verbatim.

pip install labelixa
from labelixa import Client

c = Client()                        # anonymous; Client(api_key="lbx_...") for your quota
png = c.render_png("^XA^CF0,60^FO50,50^FDHello^FS^XZ", width_in=4, height_in=6)
open("label.png", "wb").write(png)

report = c.validate("^XA^QQ^FDx^XZ")  # structured lint report
epl = c.to_epl("^XA^CF0,60^FO50,50^FDHello^FS^XZ")         # ZPL -> EPL2

Official Node.js SDK

The same surface for Node — zero dependencies (built-in fetch, Node 18+), TypeScript types included.

npm install labelixa
import { Client } from "labelixa";

const c = new Client();             // anonymous; new Client({ apiKey: "lbx_..." })
const png = await c.renderPng("^XA^CF0,60^FO50,50^FDHello^FS^XZ", { widthIn: 4, heightIn: 6 });
await writeFile("label.png", png);

const report = await c.validate("^XA^QQ^FDx^XZ");
const epl = await c.toEpl("^XA^CF0,60^FO50,50^FDHello^FS^XZ");

Official Go SDK

The same surface for Go — standard library only, cancellation through context; quota errors are told apart with labelixa.AsQuotaError and carry RetryAfter.

go get github.com/Labelixa/labelixa-sdk/go
import labelixa "github.com/Labelixa/labelixa-sdk/go"

c := labelixa.New(labelixa.Options{}) // anonymous; Options{APIKey: "lbx_..."} for your quota
ctx := context.Background()
png, err := c.RenderPNG(ctx, "^XA^CF0,60^FO50,50^FDHello^FS^XZ",
	labelixa.RenderOptions{WidthIn: 4, HeightIn: 6})
if err != nil {
	log.Fatal(err)
}
os.WriteFile("label.png", png, 0o644)

report, err := c.Validate(ctx, "^XA^QQ^FDx^XZ", labelixa.ValidateOptions{})
epl, err := c.ToEPL(ctx, "^XA^CF0,60^FO50,50^FDHello^FS^XZ", labelixa.RenderOptions{}) // ZPL -> EPL2

Official MCP server (AI assistants)

Claude Desktop, Claude Code and other MCP clients can use Labelixa directly as a tool: render, validate, debug and convert ZPL, EPL, TSPL and CPCL labels and generate barcodes. Connect to the remote server at https://api.labelixa.com/mcp (nothing to install; also listed in the official MCP Registry as com.labelixa/zpl and on Smithery), or run it locally:

npm install -g labelixa-mcp
{
  "mcpServers": {
    "labelixa": {
      "command": "npx",
      "args": ["-y", "labelixa-mcp"],
      "env": {"LABELIXA_API_KEY": "lbx_..."}
    }
  }
}

Official VS Code extension

Renders the ZPL block under your cursor inside the editor and lints as you type, with findings at their real line and column in the Problems panel, quick-fixes for the findings the API already knows how to fix, and hover help for ZPL commands from the same dictionary as the reference pages. Linting never consumes label quota; rendering a preview does, so it only runs on command. The API key is kept in the editor's secret store (command: Labelixa: Set the API key), never in a settings file, and nothing is sent from an untrusted workspace.

VS Code Marketplace
code --install-extension labelixa.labelixa-zpl

The same extension is also published on Open VSX for Cursor, VSCodium, Gitpod, Theia and other editors that use that registry: search for Labelixa ZPL in the extensions view.

JetBrains IDE plugin

The Labelixa ZPL plugin on JetBrains Marketplace renders the ^XA…^XZ block under your cursor in a Labelixa Preview tool window and, with Labelixa: Validate ZPL, marks findings at their real line and column in the editor — in IntelliJ IDEA, PyCharm, WebStorm, Rider, GoLand and the other JetBrains IDEs (platform 2024.1 and newer). Install it from Settings → Plugins → Marketplace by searching for Labelixa ZPL. The API key is optional and kept in the IDE password safe.

Rendering a ZPL label to PNG

Python (requests)
import requests
r = requests.post("https://api.labelixa.com/v1/printers/8dpmm/labels/4x6/0",
                  data="^XA^CF0,60^FO50,50^FDHello^FS^XZ")
open("label.png", "wb").write(r.content)
print(r.headers.get("X-Warnings"))
Node.js (fetch)
const res = await fetch("https://api.labelixa.com/v1/printers/8dpmm/labels/4x6/0", {
  method: "POST", body: "^XA^CF0,60^FO50,50^FDHello^FS^XZ"
});
const buf = Buffer.from(await res.arrayBuffer());
require("fs").writeFileSync("label.png", buf);
PHP (cURL)
<?php
$ch = curl_init("https://api.labelixa.com/v1/printers/8dpmm/labels/4x6/0");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "^XA^CF0,60^FO50,50^FDHello^FS^XZ");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
file_put_contents("label.png", curl_exec($ch));
C# (HttpClient)
using var http = new HttpClient();
var zpl = new StringContent("^XA^CF0,60^FO50,50^FDHello^FS^XZ");
var res = await http.PostAsync(
    "https://api.labelixa.com/v1/printers/8dpmm/labels/4x6/0", zpl);
res.EnsureSuccessStatusCode();
File.WriteAllBytes("label.png", await res.Content.ReadAsByteArrayAsync());
Console.WriteLine(res.Headers.TryGetValues("X-Warnings", out var w)
    ? string.Join(", ", w) : "");
Java (java.net.http)
HttpClient http = HttpClient.newHttpClient();
HttpRequest req = HttpRequest.newBuilder()
    .uri(URI.create("https://api.labelixa.com/v1/printers/8dpmm/labels/4x6/0"))
    .POST(HttpRequest.BodyPublishers.ofString("^XA^CF0,60^FO50,50^FDHello^FS^XZ"))
    .build();
HttpResponse<byte[]> res = http.send(req,
    HttpResponse.BodyHandlers.ofByteArray());
Files.write(Path.of("label.png"), res.body());
System.out.println(res.headers().firstValue("X-Warnings").orElse(""));

Generating a barcode

cURL
curl "https://api.labelixa.com/v1/barcodes?type=ean13&data=869012345678" > product.png
Python (requests)
import requests
r = requests.get("https://api.labelixa.com/v1/barcodes",
                 params={"type": "ean13", "data": "869012345678"})
open("product.png", "wb").write(r.content)
C# (HttpClient)
using var http = new HttpClient();
var url = "https://api.labelixa.com/v1/barcodes?type=ean13&data=869012345678";
File.WriteAllBytes("product.png", await http.GetByteArrayAsync(url));
Java (java.net.http)
HttpClient http = HttpClient.newHttpClient();
HttpRequest req = HttpRequest.newBuilder()
    .uri(URI.create(
        "https://api.labelixa.com/v1/barcodes?type=ean13&data=869012345678"))
    .build();
HttpResponse<byte[]> res = http.send(req,
    HttpResponse.BodyHandlers.ofByteArray());
Files.write(Path.of("product.png"), res.body());

PDF and multiple labels

cURL — 2x3 grid on A4
curl -X POST "https://api.labelixa.com/v1/printers/8dpmm/labels/4x2/" \
     --data-binary @labels.zpl -H "Accept: application/pdf" \
     -H "X-Page-Size: A4" -H "X-Page-Layout: 2x3" > labels.pdf
PHP (cURL) — one page per label
<?php
$ch = curl_init("https://api.labelixa.com/v1/printers/8dpmm/labels/4x6/");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents("labels.zpl"));
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Accept: application/pdf"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$pdf = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) {
    throw new RuntimeException("Labelixa: " . $pdf);
}
file_put_contents("labels.pdf", $pdf); // one page per label