Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Drivers and templates for thermal printers

Project Description

Python library for communicating with line-mode thermal printers. Currently works only with printers that support the star line mode protocol but adding support for other similar printers should be possible.

Also provides a module for compiling an xml description of a page to a list of commands.

Developed at Newman Online Ltd and open sourced with permission.


Basic, without template system:

from linemode import open_printer

printer = open_printer('star+lpt:///dev/usb/lp0')

    ('write', "Hello world\n"),

Running templates:

from linemode import open_printer
from linemode.renderers import xml

printer = open_printer('star+lpt:///dev/usb/lp0')

    <bold>Hello world</bold>

With jinja:

from jinja2 import Template

from linemode import open_printer
from linemode.renderers import xml

printer = open_printer('star+lpt:///dev/usb/lp0')

# jinja2 template
template = """
  {% for potatoes in [1, 2, 3, 4] %}
    {{ potatoes }} potato
  {% endfor %}
# line mode printer document
document = Template(template).render()

# iterator of generic printer instructions
commands = xml.render(document)

# printer specific compiled representation
program = printer.compile(commands)


Command Language

Printer drivers accept an iterable of command tuples. Tuples should contain a command name followed by any number of primitive arguments. For convenience, a tuple containing just a command name can be replaced with the command name.

The following commands are supported:

Reset everything to it’s initial state.
Toggle printing bold text.
Toggle printing white on black instead of black on white.

Set the line height for the current line and all following lines. If not sent at the beginning of a new line then behaviour is undefined. Characters should remain the same width.

Default: fontsize-small

write <string>
Print the contents of a unicode string. If any characters are unsupported, they will be replaced with ‘?’.
barcode <style> <data>
Flush the line buffer and start a new line.
Create a cut at the next mark
Create a perforated cut at the next mark
Create a cut at the current cursor position
Create a perforated cut at the current cursor position


Please post any problems or feature requests using the issue tracker. Pull requests welcome. New drivers would be greatly appreciated.

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


Download Files

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

File Name & Hash SHA256 Hash Help Version File Type Upload Date
(10.5 kB) Copy SHA256 Hash SHA256
Source Mar 16, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting