How to use Python for coding with ZPL?

ZPL-Zebra Programming Language is used for communicating with Zebra Printers. They are mostly used for RFID and Bar-code printing. As ever, I wanted a bit more control over how my ZPL printer worked and had to get working.
The easiest technique is of course Python. And this is how I did it.

First get the Zebra package from Pypi
pypi.python.org/pypi/zebra/#downloads

Installation is simple. From commandline navigate to the folder containing setup.py and then enter
python setup.py install   [Windows Only]

I presume you've installed all necessary drivers. If you are using Win 7, Windows would have automatically installed them for you. If you're on Linux, you'd need a CUPS driver. Just look at the documentation.

Example Program:
###START OF CODE###

#ZPL commands to be sent to your Printer
label="""
^XA
^FO10,10
^A0,40,40
^FD
Hello World
^FS
^XZ
"""

#End of ZPL commands to print Hello World

from zebra import zebra
z=zebra
z.getqueues                                      #This will return a list of printers installed on your computer. 
z.setqueues('ZDesigner_ZPL_200')  #Set the default printer to your new ZPL printer
z.output(label)                                  #Have fun sending data to your printer.It's as easy as it can get. :)


####END OF CODE####


Reference:
http://bytes.com/topic/python/answers/24160-zebra-printing-language
http://pypi.python.org/pypi/zebra/

Contributors