Barcodes are everywhere: on parcels, pallets, shelf labels, shipping documents, and tickets. And more and more of them are read not by handheld scanners, but by software running on servers, robots, and edge devices. If you want to build a Python barcode scanner for such a platform, two open-source libraries come up again and again: ZXing-cpp and PyZBar.
In this blog, we’ll take a close look at both. We’ll cover their key features, supported barcode types, and limitations, then compare them side by side to help you decide which one fits your project.
In short
- ZXing-cpp is an actively maintained C++ barcode library with official Python bindings. It reads and writes most common 1D and 2D barcodes, including QR Code, Data Matrix, Aztec, and PDF417.
- PyZBar is a lightweight Python wrapper for the ZBar C library. It reads 1D barcodes and QR codes, but no other 2D symbologies, and its last release dates back to March 2022.
- For most new Python projects, ZXing-cpp is the better open-source choice thanks to its broader format support and active development. PyZBar remains a solid option for simple 1D and QR code scanning.
For production use cases such as warehouse automation, robotics, or high-volume server-side scanning, a commercial SDK like the Scanbot Linux Barcode Scanner SDK offers higher accuracy in challenging conditions, more symbologies, and enterprise support.
Why use Python for barcode scanning?
Python is the go-to language for computer vision, automation, and backend services – which makes it a natural fit for barcode scanners other than mobile apps:
- A rich computer vision ecosystem: Libraries like OpenCV, Pillow, and NumPy make it easy to capture camera frames and preprocess images before decoding.
- Fast development: Small teams can go from prototype to working scanner in hours instead of days.
- Runs almost anywhere: The same script runs on a cloud server, a Raspberry Pi, or an NVIDIA Jetson mounted on a robot.
- Easy integration: Scan results flow straight into web APIs, databases, and warehouse management systems.
A side-by-side comparison: ZXing-cpp vs. PyZBar
Open-source libraries are free to use and a great fit for prototypes and internal tools. The trade-off: When you run into a bug or an unsupported barcode type, you depend on the community (or your own team) to fix it.
With that caveat out of the way, let’s take a look at the two most popular open-source options for Python: ZXing-cpp and PyZBar.
ZXing-cpp
ZXing-cpp is a C++ barcode library that started as a port of the Java-based ZXing (“Zebra Crossing”) library. Since then, it has seen a number of quality and performance improvements. Unlike the original Java project, which is in maintenance mode, ZXing-cpp is actively developed.
Key features and benefits
The official Python bindings are available on PyPI and come as prebuilt wheels for Windows, macOS, and Linux on both x86-64 and ARM64. That means you can usually install it with a single pip install zxing-cpp – no compiler needed. It accepts images loaded with OpenCV, Pillow, or NumPy, and returns each barcode’s content, format, and position.
ZXing-cpp can also generate barcodes, which comes in handy for testing your scanning pipeline. Like the original ZXing, it is a low-level library: It decodes images, but doesn’t handle camera access or provide a scanning UI.
Supported barcodes
ZXing-cpp supports a broad range of 1D and 2D symbologies:
- 1D barcodes: UPC-A, UPC-E, EAN-8, EAN-13, GS1 DataBar, DataBar Expanded, DataBar Limited, Code 39, Code 93, Code 128, Codabar, ITF, and DX Film Edge.
- 2D barcodes: QR Code, Micro QR Code, rMQR Code, Data Matrix, Aztec, PDF417, and MaxiCode (partial support).
Limitations
- Accuracy in difficult conditions: Like most open-source decoders, ZXing-cpp struggles with damaged, blurry, or poorly lit barcodes, and with barcodes captured at steep rotation angles.
- No camera handling or UI: You’ll need to build the image capture, live preview, and user feedback yourself, for example with OpenCV.
- Building from source is demanding: Prebuilt wheels cover the most common platforms. On others, such as Alpine Linux or other musl-based systems, you need a C++20 compiler to build the package yourself.
- Recent Python versions only: The latest release requires Python 3.10 or higher, which can be a hurdle on older embedded systems.
- No postal codes: Postal symbologies like USPS Intelligent Mail or Royal Mail 4-State are not supported.
PyZBar
PyZBar is a Python wrapper for ZBar, a long-established open-source C library for reading barcodes. PyZBar is lightweight and has no dependencies other than the ZBar library itself, which makes it a popular choice in small projects.
Key features and benefits
PyZBar works with Pillow images, OpenCV and NumPy arrays, and raw image bytes. For each barcode it finds, it returns the decoded data, the symbology, a bounding box, and a polygon around the code. It can scan multiple barcodes in a single image. With newer ZBar versions, it also reports the barcode’s orientation and a relative quality score. You can also limit the search to specific symbologies, which speeds up decoding and avoids unintended reads.
On Linux and macOS, you need to install the ZBar shared library first. On Windows, the required DLLs ship with the Python package.
Supported barcodes
PyZBar can read everything the installed ZBar version supports:
- 1D barcodes: EAN-13/UPC-A, UPC-E, EAN-8, Code 39, Code 93, Code 128, Codabar, Interleaved 2 of 5, GS1 DataBar, and DataBar Expanded.
- 2D barcodes: QR Code only (plus SQ Code in recent ZBar versions).
Limitations
- Very limited 2D support: Data Matrix, Aztec, and PDF417 are not supported. That rules out PyZBar for many logistics, healthcare, and ID document use cases.
- Dormant development: The latest PyZBar release, version 0.1.9, came out in March 2022 and was tested on Python versions up to 3.10 (PyPI). The underlying ZBar library is still maintained in a community fork, but updates are infrequent.
- Native dependency: You need to install the ZBar shared library separately on Linux and macOS. Its version determines which features (like orientation detection) are available.
- Accuracy in difficult conditions: ZBar can struggle with blurry, damaged, low-contrast, or rotated barcodes, especially in live camera feeds.
- LGPL licensing: PyZBar itself is MIT-licensed, but ZBar is licensed under the LGPL 2.1. Check whether this is compatible with how you distribute your software.
Summary: ZXing-cpp vs PyZBar
| Feature | ZXing-cpp | PyZBar |
| What it is | C++ library with Python bindings | Python wrapper for the ZBar C library |
| Supported barcodes | Most common 1D and 2D codes, incl. QR, Data Matrix, Aztec, PDF417 | 1D codes and QR Code |
| Base library | ZXing-cpp (C++ port of ZXing) | ZBar (C) |
| Maintenance status | Actively maintained | Dormant (last release March 2022) |
| License | Apache 2.0 | MIT (wrapper), LGPL 2.1 (ZBar) |
| Installation | pip install zxing-cpp (native code bundled in the wheel) | pip install pyzbar plus a system ZBar library on macOS and Linux |
| Python version | 3.10+ | Tested on 2.7 and 3.5 – 3.10 |
| UI | None | None |
| Input sources | Images and video frames (OpenCV, Pillow, NumPy) | Images and video frames (Pillow, OpenCV, NumPy, raw bytes) |
| Barcode generation | Yes | No |
| Best for | New projects that need broad 1D and 2D coverage (incl. Data Matrix and PDF417), barcode generation, and a simple pip-only install across Linux, macOS, Windows, and ARM. | Existing projects or older Python versions that only need 1D barcodes and QR codes, with bounding polygons and orientation for each code. |
Which barcode scanner should you use?
The best way to find out is to test both libraries with real images from your use case, ideally including blurry, damaged, and poorly lit ones.
Before you do, these six questions will help you narrow down your choice:
- Which barcode types do you need to scan? If you need anything beyond 1D codes and QR codes, such as Data Matrix (e.g., on electronic components) or PDF417 (e.g., on shipping labels and IDs), PyZBar is not an option.
- How actively is the library developed? Active maintenance means bug fixes, support for new Python versions, and security patches. A dormant project may stop working after your next system upgrade.
- Do you have privacy or offline requirements? Both libraries run fully on-device, so no image data leaves your system. This is a big plus compared to cloud-based barcode APIs.
- How well does it need to scale? Scanning a handful of images a day is different from processing thousands of camera frames per hour on a robot. Benchmark speed and read rates under realistic conditions.
- Is it for personal or commercial use? Check the license. Apache 2.0 (ZXing-cpp) is very permissive, while the LGPL 2.1 (ZBar) imposes obligations when you distribute your software.
- What’s your budget – including engineering time? Open-source libraries are free to use, but building camera handling, preprocessing, and workarounds for edge cases costs developer hours.
When to choose which Python library
ZXing-cpp is the better default for most new Python projects, as it is in active development. Choose it when:
- You need support for a wider range of symbologies, especially for 2D barcodes.
- You also need to generate barcodes.
- You want a pip-only install that works the same on Linux, macOS, and Windows, including on ARM architectures.
Choose PyZBar when:
- You only need 1D barcodes and QR codes.
- You are already using it in an existing project
,or work on older systems with Python versions below 3.10. - You want bounding polygons and orientation for each code.
Open-source libraries are a great fit for personal projects, prototypes, and internal tools. For mission-critical applications, where every missed scan costs time and money, a commercial SDK with dedicated support is usually the better choice.
The commercial alternative: Scanbot Barcode Scanner SDK
We developed the Scanbot Barcode Scanner SDK to help companies overcome the hurdles of free barcode scanning software. The Scanbot Linux Barcode Scanner SDK brings our scanning engine to servers, desktops, and edge devices – with native APIs for Python, C, Java, and Node.js.
- Runs fully on-device: No internet connection is required, and no image data ever leaves your system.
- Runs where you need it: Any x86_64 or ARM64 Linux system with glibc 2.27 or higher, including Raspberry Pi 5 and NVIDIA Jetson devices, with GPU acceleration on Jetson Orin.
- Reliable in challenging conditions: Fast, accurate results even on low-power hardware, in low light, or with damaged barcodes.
- Extensive symbology support: All common 1D and 2D barcodes, including GS1 DataBar, Data Matrix, PDF417, Aztec, and postal codes.
- Transparent pricing: A flat annual license fee with unlimited scans.
Cypher Robotics: A logistics and warehousing case study
In warehouses, barcodes are increasingly read by cameras on robots, drones, and conveyors instead of handheld scanners – for inventory cycle counting, goods receiving, sorting, track and trace, and more. These environments are tough for any barcode scanner: labels are damaged or covered in plastic wrap, lighting varies, the cameras are in motion, and Wi-Fi coverage is often patchy. That’s exactly the challenge Cypher Robotics set out to solve.
Cypher Robotics develops autonomous robotic solutions for warehouses. Its automated cycle counting system uses robots carrying a tethered drone that scans barcodes on warehouse shelves. For this, the company needed a reliable barcode scanner that fits seamlessly into its clients’ systems and runs directly on the robot.
“Scanbot SDK not only helped us identify the challenge of transitioning our client from 1D to 2D barcodes, but also instigated a crucial shift in the client’s mindset, urging them to embrace these technological advancements for heightened efficiency and effectiveness.”
How to build a Python barcode scanner with the Scanbot SDK on Linux and Windows
In the following, we’ll show you how to build a simple command-line barcode scanner in Python with the Scanbot Barcode Scanner SDK. It reads all barcodes from an image file and prints their values in the terminal. The setup differs slightly between Linux and Windows, so some steps come in two versions.
You can find more examples, including live scanning from a camera, in our example repository on GitHub.
Requirements on Linux:
- A Linux system with glibc 2.27 or higher on x86_64 or ARM64 (for example Ubuntu, Debian, Raspberry Pi OS 64-bit, or NVIDIA Jetson)
- Python 3.6 or higher with pip, setuptools, and wheel
Requirements on Windows:
- A Windows PC with an x86 or x86_64 CPU
- Python 3.6 or higher (32-bit or 64-bit)
- PowerShell (the Windows commands below are written for PowerShell, not cmd)
On both platforms, you’ll also need a Scanbot SDK license key. You can request a free trial license on our website.
Step 1: Install Python and OpenCV
Linux
First, install the Python virtual environment module and OpenCV:
sudo apt update
sudo apt install -y python3-venv python3-opencv
If you’re using an NVIDIA Jetson and want to enable GPU acceleration, you’ll need at least JetPack 6.1, CUDA 12.6, and TensorRT 10.3. You can install the required packages with:
sudo apt install -y nvidia-l4t-cuda libnvinfer10 libnvinfer-plugin10 libnvonnxparsers10
Windows
Make sure Python 3.6 or higher is installed and available in PowerShell. You can check this with:
python --version
On Windows, you’ll install OpenCV with pip in the next step.
Step 2: Create and activate a virtual environment
Linux
Next, create a virtual environment and update its packaging tools. The --system-site-packages flag lets the environment use the OpenCV package you’ve just installed:
python3 -m venv .env --system-site-packages
source .env/bin/activate
pip install --upgrade pip setuptools wheel
Windows
Next, create and activate a virtual environment, update its packaging tools, and install OpenCV:
python -m venv .env --system-site-packages
. .\.env\Scripts\Activate.ps1
python -m pip install --upgrade pip setuptools wheel
python -m pip install opencv-python
Step 3: Install the Scanbot SDK
Now install the Scanbot SDK package for your platform. Replace <SCANBOT_SDK_VERSION> with the version you want to install. You can find all versions on the releases page of our example repository.
Linux
For ARM64 devices (e.g., Raspberry Pi or NVIDIA Jetson):
export SCANBOT_SDK_VERSION=<SCANBOT_SDK_VERSION>
pip install https://github.com/doo/scanbot-sdk-example-linux/releases/download/standalone-sdk%2Fv${SCANBOT_SDK_VERSION}/scanbotsdk-${SCANBOT_SDK_VERSION}-py3-none-linux_aarch64.whl
For x86_64 machines:
export SCANBOT_SDK_VERSION=<SCANBOT_SDK_VERSION>
pip install https://github.com/doo/scanbot-sdk-example-linux/releases/download/standalone-sdk%2Fv${SCANBOT_SDK_VERSION}/scanbotsdk-${SCANBOT_SDK_VERSION}-py3-none-linux_x86_64.whl
Then verify that the installation was successful:
python -c "import scanbotsdk; print('scanbotsdk OK')"
💡 On a Jetson, run sudo jetson_clocks --store followed by sudo jetson_clocks to prevent throttling and get maximum performance. Use sudo jetson_clocks --restore to go back to the default settings.
Windows
First, set the version variable:
$SCANBOT_SDK_VERSION = "<SCANBOT_SDK_VERSION>"
Then install the package that matches your Python installation.
For 64-bit Python (x86_64):
pip install https://github.com/doo/scanbot-sdk-example-linux/releases/download/standalone-sdk%2Fv${SCANBOT_SDK_VERSION}/scanbotsdk-${SCANBOT_SDK_VERSION}-py3-none-win_amd64.whl
For 32-bit Python (x86):
pip install https://github.com/doo/scanbot-sdk-example-linux/releases/download/standalone-sdk%2Fv${SCANBOT_SDK_VERSION}/scanbotsdk-${SCANBOT_SDK_VERSION}-py3-none-win32.whl
Then verify that the installation was successful:
python -c "import scanbotsdk"
If the command runs without an error, the SDK is installed.
Step 4: Create the project
Create a project folder with a single Python file.
Linux
mkdir -p barcode-quickstart-python && \
touch barcode-quickstart-python/main.py
Windows
New-Item -ItemType Directory -Force barcode-quickstart-python
New-Item -ItemType File barcode-quickstart-python\main.py
Step 5: Initialize the SDK
The following steps are the same on Linux and Windows.
Open main.py. Before you can use any of the Scanbot SDK’s features, you need to initialize it with your license key. The following function does that and checks whether the license is valid:
def run_barcode_scanner(image: ImageRef) -> None:
config = BarcodeScannerConfiguration()
scanner = BarcodeScanner(configuration=config)
result = scanner.run(image=image)
if not result.barcodes:
print("No barcodes found.")
return
for idx, barcode in enumerate(result.barcodes, 1):
print(f"{idx}) {barcode.text} [{barcode.format}]")
Step 6: Create and run the barcode scanner
Next, create a barcode scanner with the default configuration, run it on the image, and print the value and format of each barcode it finds:
def run_barcode_scanner(image: ImageRef) -> None:
config = BarcodeScannerConfiguration()
scanner = BarcodeScanner(configuration=config)
result = scanner.run(image=image)
if not result.barcodes:
print("No barcodes found.")
return
for idx, barcode in enumerate(result.barcodes, 1):
print(f"{idx}) {barcode.text} [{barcode.format}]")
Your final main.py looks like this:
import sys
import scanbotsdk
from scanbotsdk import (
LicenseStatus,
ImageRef,
BarcodeScanner,
BarcodeScannerConfiguration,
)
SCANBOT_LICENSE_KEY = "<SCANBOTSDK-LICENSE-KEY>"
def initialize_sdk() -> None:
scanbotsdk.initialize(SCANBOT_LICENSE_KEY)
license_info = scanbotsdk.get_license_info()
print(f"License Status: {license_info.status}")
if license_info.status != LicenseStatus.OKAY:
raise SystemExit("Invalid or expired license. Exiting.")
def run_barcode_scanner(image: ImageRef) -> None:
config = BarcodeScannerConfiguration()
scanner = BarcodeScanner(configuration=config)
result = scanner.run(image=image)
if not result.barcodes:
print("No barcodes found.")
return
for idx, barcode in enumerate(result.barcodes, 1):
print(f"{idx}) {barcode.text} [{barcode.format}]")
def main():
if len(sys.argv) < 2:
print("Usage: python main.py <image_path>")
return
image_path = sys.argv[1]
initialize_sdk()
image = ImageRef.from_path(image_path)
run_barcode_scanner(image)
if __name__ == "__main__":
main()
Step 7: Scan your first barcodes
Now run the script from inside your project folder and pass it the path to an image containing barcodes. On Linux:
python main.py /path/to/image_with_barcodes.jpg
On Windows:
python main.py C:\path\to\image_with_barcodes.jpg
The values and formats of all detected barcodes will be printed in your terminal. And that’s it – you’ve built a barcode scanner in Python with the Scanbot SDK!
From here, you can go further: scan barcodes from a live camera stream, restrict the scanner to specific barcode types, or check out the Python API reference for all available options.
Should you have questions or run into any issues, we’re happy to help! Just shoot us an email via tutorial-support@scanbot.io.
Happy scanning! 🤳
FAQ
What is the best open-source barcode scanner for Python?
For most new projects, ZXing-cpp is the best open-source barcode scanner for Python. It supports the widest range of 1D and 2D barcodes, including QR Code, Data Matrix, Aztec, and PDF417, installs via pip without system dependencies, and is actively maintained. PyZBar is a good alternative if you only need 1D barcodes and QR codes.
What is the difference between ZXing-cpp and PyZBar?
ZXing-cpp is a C++ barcode library with official Python bindings that reads and writes most 1D and 2D barcode types. PyZBar is a Python wrapper for the ZBar C library that only reads 1D barcodes and QR codes. ZXing-cpp is actively developed, while PyZBar’s last release was in March 2022.
Is PyZBar still maintained?
Only lightly. PyZBar’s latest release, version 0.1.9, came out in March 2022, and its README lists Python 3.10 as the newest tested version. The ZBar library itself still receives occasional updates in its community fork. PyZBar still works for simple jobs, but you should expect little new development.
How do I install ZXing-cpp and PyZBar in Python?
Install ZXing-cpp with pip install zxing-cpp. Install PyZBar with pip install pyzbar. On Linux, PyZBar also requires the ZBar shared library (sudo apt-get install libzbar0), and on macOS, brew install zbar.
How do I read barcodes from PDF files in Python?
ZXing-cpp and PyZBar can’t open PDFs directly, so you have to render each page as an image first. For server-side barcode extraction from PDF documents, we recommend the Barcode Extraction Module of the Apryse Server SDK. It works directly on PDF files, supports more than 100 barcode types, is available for Python, and returns the results as JSON.
Which barcode scanner is best for warehouse and logistics automation?
Warehouse automation requires high read rates on damaged, wrinkled, or distant labels, and scanning must often work offline. Open-source libraries can struggle under these conditions. Cloud-based scanning is impractical. The Scanbot Linux Barcode Scanner SDK runs fully on-device and is used by Cypher Robotics in its autonomous inventory cycle counting system.
Does the Scanbot Linux Barcode Scanner SDK need an internet connection?
No. The Scanbot SDK processes all images on-device. No internet connection is required, and no image data leaves your system.