Socket
Book a DemoInstallSign in
Socket

pyrxing

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pyrxing

A barcode reader extension module using zxing-cpp and pyo3

0.4.1
pipPyPI
Maintainers
1

pyrxing

pyrxing is a fast, dependency-free Python barcode/QR code reader built using zxing-cpp Rust bindings via PyO3.

This library offers efficient barcode scanning in pure Python environments, with pre-built native wheels — including full support for Alpine Linux and musl-based systems where the official zxing-cpp Python package requires additional build steps.

🚀 Features

  • High performance: Powered by zxing-cpp C++ library through optimized Rust bindings with excellent multiple barcode detection performance
  • 🐍 Python-native API: Simple interface with just two functions: read_barcode and read_barcodes
  • 📦 No system dependencies: No need for zbar, JRE, or any external libraries
  • 🏗 Alpine Linux compatible: Pre-built musllinux wheels available (no build required)
  • 🧠 Type hinting & autocompletion: Includes .pyi stub files
  • 🔒 Safe and minimal: No unnecessary features — just barcode reading
  • Competitive performance: Outperforms zxing-cpp on 65.0% of formats in single detection and 80.0% in multiple detection

✅ Supported Environments

Platforms

  • Linux (manylinux & musllinux wheels)
    • Architectures: x86_64, aarch64
  • macOS
    • Universal binaries for both Intel and Apple Silicon (arm64)
  • Windows
    • Architectures: x64, x86

Python Versions

Python 3.11+

📦 Installation

Install with pip:

pip install pyrxing

Recommended for Alpine Linux/musl environments: While the official zxing-cpp Python package requires building from source on musl-based systems, pyrxing provides pre-built wheels for immediate installation.

📊 Performance

pyrxing delivers excellent performance across a comprehensive range of barcode formats, with particularly strong advantages in multiple barcode detection scenarios:

Performance Summary:

  • Single detection: pyrxing outperforms zxing-cpp on 13 out of 20 formats (65.0%)
  • Multiple detection: pyrxing outperforms zxing-cpp on 16 out of 20 formats (80.0%)

Benchmark Results (μs per decode)

read_barcode() - Single Barcode Detection

Formatpyrxingzxing-cppImprovement
UPC-E555.9710.828% faster
Data Matrix260.0330.927% faster
EAN-8881.81048.219% faster
UPC-A1159.51358.517% faster
EAN-131161.71328.414% faster
Code 391063.51212.814% faster
ITF336.2382.314% faster
Code 1282272.22541.012% faster
Codabar415.1468.113% faster
MaxiCode947.51026.08% faster
PDF417369.6400.18% faster
Aztec85.992.87% faster
DX Film Edge302.1314.14% faster
QR Code294.5292.31% slower
Code 93281.3276.32% slower
Micro QR75.473.13% slower
rMQR84.684.30% (tied)
DataBar198.5196.91% slower
DataBar Exp.358.3356.11% slower
DataBar Ltd.196.6186.65% slower

read_barcodes() - Multiple Barcode Detection

Formatpyrxingzxing-cppImprovement
UPC-A4500.04817.07% faster
Codabar1248.81341.47% faster
EAN-82683.32854.96% faster
UPC-E1962.72062.05% faster
ITF1039.51085.94% faster
Code 393078.03206.54% faster
PDF417851.1883.74% faster
EAN-134566.94739.64% faster
Code 1287769.58014.23% faster
Aztec558.3575.13% faster
DX Film Edge1572.91609.02% faster
MaxiCode2509.32561.32% faster
Data Matrix1002.51082.38% faster
rMQR466.5471.91% faster
QR Code2203.32205.60% faster
Micro QR407.0407.80% faster
Code 93950.5937.81% slower
DataBar670.4666.91% slower
DataBar Exp.1300.41279.22% slower
DataBar Ltd.629.3620.71% slower

Benchmark Environment

  • OS: macOS 15.5 (Apple Silicon)
  • CPU: Apple M1 Max (10-core)
  • Python: 3.13.3
  • Libraries: pyrxing (current), zxing-cpp 2.3.0, Pillow 11.3.0
  • Method: Median of 100 runs with 20-run warm-up

Test Images: Located in pyrxing/assets/ directory:

  • 1D Barcodes: test_codabar.png, test_code39.png, test_code93.png, test_code128.png, test_ean8.png, test_ean13.png, test_itf.png, test_upc_a.png, test_upc_e.png, test_data_bar.png, test_data_bar_expanded.png, test_data_bar_limited.png
  • 2D Barcodes: test_qr_code.png, test_micro_qr.png, test_rmqr.png, test_aztec.png, test_data_matrix.png, test_pdf417.png, test_maxi_code.png
  • Specialty: test_dx_film_edge.png

Reproduce benchmarks: See pyrxing/benchmark.py for the complete benchmark script.

🧪 Usage

from pyrxing import read_barcode, read_barcodes

# Read a single barcode from an image path
barcode = read_barcode("example.png")

# Read multiple barcodes from an image
barcodes = read_barcodes("example.png")

# Optionally filter by barcode format
barcodes = read_barcodes("example.png", formats=['QRCode'])

You can also pass an object that conforms to the ImageProtocol instead of a path.

from pyrxing import read_barcode
from PIL import Image
# Read a single barcode from PIL.Image.Image object
barcode = read_barcode(Image.open("example.png"))

🛠 Planned Features

  • More platform wheels (expanding support for other OS/Python combinations)
  • Additional barcode format configuration options

🚫 Not Planned

  • ❌ Barcode generation

📚 API Reference

For full API and type hints, see pyrxing.pyi or use your IDE's autocomplete.

from typing import Any, Literal, Protocol

BarcodeFormat = Literal[
    "Aztec",
    "Codabar",
    "Code39",
    "Code93",
    "Code128",
    "DataBar",
    "DataBarExpanded",
    "DataBarLimited",
    "DataMatrix",
    "EAN8",
    "EAN13",
    "ITF",
    "MaxiCode",
    "PDF417",
    "QRCode",
    "UPCA",
    "UPCE",
    "MicroQRCode",
    "RMQRCode",
    "DXFilmEdge",
]


class ImageProtocol(Protocol):
    @property
    def width(self) -> int: ...

    @property
    def height(self) -> int: ...

    def tobytes(self) -> bytes:
        """return pixel data as byte array"""

    def convert(self, mode: str) -> Any: ...

    def load(self): ...


class BarcodeDecodeError(Exception): ...

class ImageError(Exception): ...

class Point:
    @property
    def x(self) -> float: ...

    @property
    def y(self) -> float: ...

class DecodeResult:
    @property
    def text(self) -> str: ...

    @property
    def points(self) -> list[Point]: ...

    @property
    def format(self) -> str: ...


def read_barcode(image: str | ImageProtocol, *, formats: list[BarcodeFormat] | None = None) -> DecodeResult | None: ...
def read_barcodes(image: str | ImageProtocol, *, formats: list[BarcodeFormat] | None = None) -> list[DecodeResult]: ...

License

Apache License 2.0

Keywords

barcode

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.