Sign In
Products
ZPL PreviewBarcode GeneratorImage → ZPLZPL cheat sheetLabel DesignerTemplate Gallery
Developers
API QuickstartAPI ReferenceMCP ServerBulk GenerationWebhooksSDKs & ExamplesLimitsOn-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 ToolsAll ToolsGuidesPricing
Language
EnglishTürkçeDeutsch
HomeDevelopersCode 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 MCP server (AI assistants)

Claude Desktop, Claude Code and other MCP clients can use Labelixa directly as a tool: ZPL preview, validation and barcode generation. Use our Smithery listing for the zero-install remote server, 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 the file on save, with findings at their real line and column in the Problems panel. Linting never consumes label quota; rendering a preview does, so it only runs on command.

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

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