Barcodatron – A barcode reader / label generation environment



barcodatron is a system for reading and generating barcodes using common low-cost scanners and printers. I use it for tracking electronic components for assembly. It certainly has a wide variety of other applications, so I thought I would open-source it. It consists of python scripts which can operate stand-alone or be called as functions. They are called from the command line or, from a web interface. The web interface is implemented using Flask web server framework which is written in python.  A low-cost hand-held scanner is used to read barcodes from labels, reports, and cheat-sheets. The web interface can be used to look-up parts in an external database via RESTful http GET calls. Printed barcodes are generated using the reportlab python library which generates pdfs. The system also recognizes barcodes to generate labels which are sent to Zebra  printers, which are commonly used for shipping labels. The current environment runs under Windows XP, however it could easily be ported to IOS or Linux. The Flask framework is very lightweight and would run very well on a raspberry pi or beaglebone black



The following diagram describes the overall architecture


A web server running locally delivers .html, js, and css to render the UI. When a barcode is scanned, it will parse the request and send it to the local server which will either forward the request to an external server if it is a database look-up, or execute locally if it is a command to generate a label on the printer.


To run barcodatron you will need the following installed on your system:

Python 2.7

Available from

Git for windows

Available from You could skip it and just use the windows command prompt, but my instructions assume you are using the git bash command prompt.

Once you’ve installed git, go to into windows->control panel->system->Advanced->Environment ->Variables and add C:\python27\;C:\python27\scripts; to your $PATH


Again, not strictly necessary, but the easy_install script makes it much easier to install python libraries

From here on out the instructions assume you’ve started git bash and are entering from the command line

curl >; 

Flask & Flask Bootstrap

Available from 

easy_install flask
easy_install flask-bootstrap


Reportlab is a huge magical blob of python which lets you generate postscript (.ps,.pdf) and actually works most of the time. Documentation:

easy_install reportlab

Win32 API

Win32api allows much better access the windows API from python. We use it to call acrobat to generate the pdfs


Requests is an http protocol toolkit for python

easy_install requests


Check it out from github

git clone

Try it out

cd barcodatron

At this point you should be able to navigate to http://localhost/ and see the UI:


Print out barcode_list.pdf It contains a sheet of sample barcodes and commands. If it doesn’t exists, you can generate another one with python You can look at the source code to get an idea of how to use reportlab to generate reports and cheat-sheets with barcodes on them. The system works with triplets of information; Two nouns – A Job number and a Part number, and a Verb – A command to generate a certain kind of label. Scan the sample Job Number, then the Sample Part Number from the barcode list, then scan a command to preview a label. At this point acrobat will start and show you an image of the label.

External Database Access

The script is in charge of making queries to the external DB, but in this example, it is stubbed out and responds locally to the sample part queries that are in barcode_list.pdf At the top of the script you will see where to add a URL and key to make calls to an external web server. In my case, it is a wordpress plugin which makes use of the wordpress ajax api

# server constants
server_ajax_url = '' # server's ajax api
server_auth_key = 'fake_query' #  replace w/an auth key your server checks for

This is the work-horse script which generates the pdf for the barcode labels. It may be invoked from the command line. Use python -h to get list of commands:

python -h


    -t [ 0 = no test, 1 = test 1, 2 = test 2 ]
    -v [ 0 = no verbose, 1 = verbose ]
    -s [ 0 = 8.5 x 11 paper, 1 = 4 x 6 labels, 2 = 2.25 x 1.25 labels 3 = 3.5 x 1 ]
    -p [ <printer name>, acrobat = send to previewer ]


  Print 2 sheets of test labels on 8.5 x 11 paper to the acrobat reader:

     python -s 0 -t 1 -p acrobat -v 1

  Print 1 4x6 test label:

     python -s 1 -t 1 -p acrobat -v 1

  Print 1 2.25 x 1.25 test label:

     python -s 2 -t 1 -p acrobat -v 1


  Takes input on stdin of the format:

  First token is one of [logo,barcode,keyval]

  LOGO w/no arg renders logo512x512.png
  LOGO C renders the a very large character C in its place
  BARCODE f1 f2 renders a barcode consisting of f1:f2, then renders 'f1:f2' underneath the barcode in plain text
  KEYVAL f1 f2 f3 fn renders 'f1:' in bold, followed by 'f2 f3 fn', wrapping text lines if necessary

  See tgetl.testlines in source code for example input