Open Barcode for Python

A typed package built with a standard pyproject.toml and a unittest suite. No third-party imports.

Package registryPyPI
RuntimePython 3.10 or newer
LicenseApache-2.0

Install

Installbash
pip install openbarcode

Generate a barcode

Examplepython
from openbarcode.linear import UPC
bars = UPC("03600029145").barcode()  # 95 modules

The example encodes UPC-A 03600029145, which gets check digit 2 and produces 95 modules. The same input gives the same modules in every Open Barcode library.

More examples

Each example uses the same modules as the tests, so the output matches the other languages.

Three barcode typespython
from openbarcode.linear import UPC, EAN, Code39

upc = UPC("03600029145").barcode()     # 95 modules
ean = EAN("400638133393").barcode()    # 95 modules
code39 = Code39("CODE39").barcode()    # 103 modules
Wrong check digitpython
from openbarcode.linear import UPC

try:
    UPC("036000291453")  # the check digit should be 2
except ValueError as err:
    print(err)

Source and tests

The source, tests and release workflow are in the Python repository on GitHub.

Other languages