python-escpos - Python library to manipulate ESC/POS Printers
Python ESC/POS is a library which lets the user have access to all those printers handled by ESC/POS commands, as defined by Epson, from a Python application.
The library tries to implement the functions provided by the ESC/POS-commandset and supports sending text, images, barcodes and qr-codes to the printer.
Text can be aligned/justified and fonts can be changed by size, type and weight.
Also, this module handles some hardware functionalities like cutting paper, control characters, printer reset and similar functions.
Since supported commands differ from printer to printer the software tries to automatically apply the right settings for the printer that you set. These settings are handled by escpos-printer-db which is also used in escpos-php.
This library makes use of:
- pyusb for USB-printers
- Pillow for image printing
- qrcode for the generation of QR-codes
- pyserial for serial printers
- python-barcode for the generation of barcodes
Documentation and Usage
The basic usage is:
from escpos.printer import Usb """ Seiko Epson Corp. Receipt Printer (EPSON TM-T88III) """ p = Usb(0x04b8, 0x0202, 0, profile="TM-T88III") p.text("Hello World\n") p.image("logo.gif") p.barcode('1324354657687', 'EAN13', 64, 2, '', '') p.cut()
Another example based on the Network printer class:
from escpos.printer import Network kitchen = Network("192.168.1.100") #Printer IP Address kitchen.text("Hello World\n") kitchen.barcode('1324354657687', 'EAN13', 64, 2, '', '') kitchen.cut()
Another example based on the Serial printer class:
from escpos.printer import Serial """ 9600 Baud, 8N1, Flow Control Enabled """ p = Serial(devfile='/dev/tty.usbserial', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=1.00, dsrdtr=True) p.text("Hello World\n") p.qr("You can readme from your smartphone") p.cut()
The full project-documentation is available on Read the Docs.
This project is open for any contribution! Please see CONTRIBUTING.rst for more information.
None of the vendors cited in this project agree or endorse any of the patterns or implementations. Its names are used only to maintain context.