flag german flag uk flag us Tip: Bookmark this page with Ctrl-D (Win) or Apple-D (Mac) MainProductsKnow How / FAQStoreContact

How to create Barcodes with Python

Using our command line tool CLIBar, creating barcodes with Python is a snap. The tool supports all common linear and 2D barcode symbologies. Set parameters over the command line, control the barcode creation with an extra options file for maximum flexibility. Suitable for individual barcodes as well as mass creation of serial barcodes.

Sample code in Python to create serial barcodes with consecutive numbers (401234567890, 401234567891 etc.):

import os

cmd_base = "clibar -o";
file_base = "-./output_";
extension = ".png";
data_base = "-d 40123456789";
options = " -f. /options.txt";

for number in range(0,10):
    cmd = cmd_base + file_base + `number` + extension + data_base + `number` + options
    os.system(cmd)

Sample for Mac OS X, for Windows paths etc. may have to be adapted. The created bar codes are written as a 300 dpi PNG to the output folder. The file options.txt controls the barcode creation; here the barcode symbology, size, resolution are set.

A fairly easy extension of the above sample would pull the data from a text file or database. The right approach if personnel or or product data had to be encoded.

The CLIBar Software is available for Mac OS X and Windows:

CLIBar Barcode Command Line Tool Mac
CLIBar Barcode Command Line Windows

Software comes with sample scripts for barcode creation in Perl, Python, Ruby and AppleScript (Mac only). For small numbers of codes the tool can also be invoked directly from the command line or the Terminal.

Back to the main FAQ index.