pyzbar

0.1.9 · maintenance · verified Sat Apr 11

pyzbar is a Python library that provides bindings for the open-source ZBar barcode reading library. It allows users to read one-dimensional barcodes and QR codes from various image sources, including PIL/Pillow images, OpenCV/NumPy ndarrays, and raw bytes. The current version is 0.1.9. While some sources suggest active maintenance and regular updates, external analysis indicates an inactive maintenance status with no new PyPI releases in the past 12 months as of late 2025.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `pyzbar` to decode barcodes from an image using the Pillow library. It opens an image file and then calls the `decode` function to extract barcode information, printing the decoded data and type. Remember to replace `image_path` with the actual path to your barcode image.

from pyzbar.pyzbar import decode
from PIL import Image
import os

# Assuming an image file named 'barcode.png' exists in the current directory
# For a real application, replace with a path to your image or a file handle
image_path = os.environ.get('PZ_TEST_IMAGE_PATH', 'pyzbar/tests/code128.png') # Using a test image from the repo for runnable example

try:
    # Open the image file using Pillow
    img = Image.open(image_path)

    # Decode any barcodes in the image
    barcodes = decode(img)

    if barcodes:
        for barcode in barcodes:
            print(f"Decoded Data: {barcode.data.decode('utf-8')}")
            print(f"Barcode Type: {barcode.type}")
            print(f"Location (Rect): {barcode.rect}")
    else:
        print("No barcodes found in the image.")

except FileNotFoundError:
    print(f"Error: Image file not found at {image_path}. Please provide a valid path.")
except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →