Skip to content
Barcode rendering for Python 2 and 3 supporting QRcode, Aztec, PDF417, I25, Code128, Code39 and many more types.
PostScript Python
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
requirements Upgrade requirements (#177) Aug 3, 2019
tests Regenerate test images with Ghostscript 9.26 (#165) Jun 19, 2019
treepoem Version 3.1.0 Jun 25, 2019
.gitignore Add .pytest_cache to .gitignore Feb 2, 2018
.travis.yml Test with latest ghostscript (#155) Jun 25, 2019
AUTHORS.rst Add myself to AUTHORS Mar 30, 2016
HISTORY.rst Version 3.1.0 Jun 25, 2019
LICENSE Settle on MIT License Mar 18, 2016 Add the missing `BWIPP` postscript files. Mar 30, 2016
README.rst Regenerate test images with Ghostscript 9.26 (#165) Jun 19, 2019
pyproject.toml Format code with Black (#164) Jun 19, 2019
setup.cfg Drop not_skip = from isort config (#166) Jun 20, 2019 Add PyPI changelog link (#178) Aug 12, 2019
tox.ini Run twine check during tests (#160) May 28, 2019



A cleverly named, but very simple python barcode renderer wrapping the BWIPP library and ghostscript command line tool.


Install from pip:

pip install treepoem

Python 3.5-3.7 supported.

You'll also need Ghostscript installed. On Ubuntu/Debian this can be installed with:

apt-get install ghostscript

On Mac OS X use:

brew install ghostscript

Otherwise refer to your distribution's package manager, though it's likely to be called ghostscript too.

There's a known issue with rendering on Ghostscript 9.22+ where images are smeared. See GitHub Issue #124 and its associated links for more details. Ghostscript merged a fix in version 9.26 and common barcodes seem to work from then on, though still with some smearing.

You can check your Ghostscript version with:

gs --version


generate_barcode(barcode_type, data, options=None)

Generates a barcode and returns it as a PIL image file object (specifically, a PIL.EpsImagePlugin.EpsImageFile).

barcode_type is the name of the barcode type to generate (see below).

data is a str (Python 2 unicode) or bytes (Python 2 bytes) of data to embed in the barcode - the amount that can be embedded varies by type.

options is a dictionary of strings-to-strings of extra options to be passed to BWIPP, as per its docs.

For example, this generates a QR code image, and saves it to a file using standard PIL

>>> import treepoem
>>> image = treepoem.generate_barcode(
...     barcode_type='qrcode',  # One of the BWIPP supported codes.
...     data='barcode payload',
... )
>>> image.convert('1').save('barcode.png')

If your barcode image is monochrome, with no additional text or coloring, converting the Image object to monochrome as shown above (image.convert('1')) will likely reduce its file size.


This is a dict of the ~100 names of the barcode types that the vendored version of BWIPP supports: its keys are strs of the barcode type encoder names, and the values are instances of BarcodeType.


A class representing meta information on the types. It has two attributes:

  • type_code - the value needed for the barcode_type argument of generate_barcode() to use this type.
  • description - the human level description of the type which has two str.

Only these common types are used in the test suite:

Command-line interface

Treepoem also includes a simple command-line interface to the functionality of generate_barcode. For example, these commands will generate two QR codes with identical contents, but different levels of error correction (see QR Code Options):

$ treepoem -o barcode1.png -t qrcode "This is a test" eclevel=H
$ treepoem -o barcode2.png -t qrcode "^084his is a test" eclevel=L parse

Complete usage instructions are shown with treepoem --help.

What's so clever about the name?


Bark ode.

Tree poem.

You can’t perform that action at this time.