Skip to main content

Print XML defined receipt on ESC/POS Printer

Project description

escpos-xml is a library to parse XML defined receipt and print it on ESC/POS Printer using python-escpos library.

The module contains a RELAX NG schema for the XML: escpos_xml/escpos.rng. The syntax is quite similar to HTML.


>>> import os
>>> from io import BytesIO, open
>>> from escpos.printer import Usb
>>> from escpos_xml import parse
>>> xml = BytesIO('''
... <receipt width="48">
...     <h1>Receipt!</h1>
...     <ul>
...         <li>
...             <span align="left" width="22">Product</span>
...             <span align="right" width="24">0.15€</span>
...         </li>
...     </ul>
...     <hr/>
...     <p size="2h">
...         <span align="left" width="24">TOTAL</span>
...         <span align="right" width="24">0.15€</span>
...     </p>
...     <barcode encoding='ean13'>
...         5449000000996
...     </barcode>
...     <cashdraw pin="2"/>
...     <cut/>
... </receipt>''')
>>> printer = Usb(0x0483, 0x5743)
>>> parse(printer, xml)
>>> parse(printer,
...      open(os.path.join('escpos_xml', 'tests', 'image.xml'), 'rb'))



The root element is receipt with the optional attribute width which is the number of character in a line.


The tags for in-line elements are: bold, b and span. The attribute available are: bold, underline, size, font, inverted and color. The span element can have also the attributes align and width.


The tags for block element are: p, h(1-5) and hr. The attributes are the same as the in-line elements with in addition the align which could be left, right or center.


It is possible to have ordered or unordered lists with the elements ol and ul. The type of bullet is defined by the attribute type. For ordered list, the start number can be specify with the start attribute. Each item is defined by an element li which has the same attributes as the in-line elements.

The list can be nested.


The barcode element print the code using the encoding attribute as format. Other attributes are: width, height, position and font.


The img element print the image defined by the src attribute using a base64 data-url format. Example:

<img src="data:image/png;base64,AAABAAMAEBAAAAEAIABoBAAANgAAAC..."/>


Some operations are available: cut, partialcut and cashdraw. The cashdraw element requires a pin attribute.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-escpos-xml-0.1.0.tar.gz (28.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page