Python
Python examples for rendering labels
Multi-page label → PDF with all pages
import requests
api_key = 'your_api_key_here'
zpl = '^XA^FO50,50^FDPage 1^FS^XZ^XA^FO50,50^FDPage 2^FS^XZ'
response = requests.post(
'https://api.zpl.tools/compatibility/labelary/v1/printers/8dpmm/labels/4x6',
headers={
'X-API-Key': api_key,
'Accept': 'application/pdf',
'Content-Type': 'application/x-www-form-urlencoded',
},
data=zpl,
)
with open('all-pages.pdf', 'wb') as f:
f.write(response.content)Multi-page label → PDF with first page only
import requests
api_key = 'your_api_key_here'
zpl = '^XA^FO50,50^FDPage 1^FS^XZ^XA^FO50,50^FDPage 2^FS^XZ'
response = requests.post(
'https://api.zpl.tools/compatibility/labelary/v1/printers/8dpmm/labels/4x6/0',
headers={
'X-API-Key': api_key,
'Accept': 'application/pdf',
'Content-Type': 'application/x-www-form-urlencoded',
},
data=zpl,
)
with open('first-page.pdf', 'wb') as f:
f.write(response.content)Multi-page label → PNG with first page only
import requests
api_key = 'your_api_key_here'
zpl = '^XA^FO50,50^FDPage 1^FS^XZ^XA^FO50,50^FDPage 2^FS^XZ'
response = requests.post(
'https://api.zpl.tools/compatibility/labelary/v1/printers/8dpmm/labels/4x6/0',
headers={
'X-API-Key': api_key,
'Accept': 'image/png',
'Content-Type': 'application/x-www-form-urlencoded',
},
data=zpl,
)
with open('first-page.png', 'wb') as f:
f.write(response.content)