pyzxing
English | 简体中文
Python bindings for the ZXing barcode decoder. PyZXing supports single and multiple barcodes, file globs, NumPy arrays, decode hints, binary payloads, result points, and orientation metadata.
Requirements
- Python 3.8 or newer
- Java 17 or newer on
PATH
PyZXing downloads and verifies its matching Java Runner automatically. The conda-forge package includes the Runner in the environment.
Installation
pip install pyzxing
or:
conda install -c conda-forge pyzxing
To install the current source tree:
git clone https://github.com/ChenjieXu/pyzxing.git
cd pyzxing
python -m pip install .
Quick start
from pyzxing import BarCodeReader
reader = BarCodeReader()
results = reader.decode("/path/to/barcode.png")
print(results)
# Decode all matching images and return one flat result list.
results = reader.decode("/path/to/images/*.png")
Restrict formats or tune decoding with keyword arguments:
results = reader.decode(
"/path/to/barcode.png",
multi=True,
try_harder=True,
pure_barcode=False,
character_set=None,
possible_formats=["QR_CODE", "DATA_MATRIX"],
)
multi: scan for multiple barcodes in one image.try_harder: use ZXing's more exhaustive decode path.pure_barcode: decode a clean, unrotated monochrome symbol.character_set: provide a charset hint when the symbol does not carry one.possible_formats: limit decoding to ZXingBarcodeFormatnames.
Results
Each result is a dictionary. Common fields are:
| Field | Type | Meaning |
|---|---|---|
filename |
bytes |
Input file URI. |
format, type |
bytes |
Barcode format and parsed-result type. |
raw, parsed |
bytes |
Backward-compatible text fields. |
text, parsed_text |
str |
Decoded and parsed display text. |
raw_bytes |
bytes | None |
ZXing raw result bytes. |
byte_segments |
list[bytes] |
Lossless byte-mode payload segments. |
points |
list[tuple[float, float]] |
Result points as (x, y) pairs. |
orientation |
0 | 90 | 180 | 270 | None |
Clockwise image rotation. |
orientation_source |
str |
metadata, derived, or unavailable. |
metadata |
dict |
Stable ZXing metadata when available. |
For binary QR data, use byte_segments instead of re-encoding text.
Decode and runtime failures raise DecodeError subclasses.
NumPy arrays
Install OpenCV and pass an RGB or grayscale array:
pip install opencv-python
results = reader.decode_array(image)
Webcam demo
The example periodically samples frames from an OpenCV camera:
pip install pyzxing opencv-python
python scripts/webcam_demo.py --camera 0 --interval 0.5
Press q or Esc to quit. Run python scripts/webcam_demo.py --help for all
options.
Command line
python scripts/scanner.py -f /path/to/barcode.png
PyInstaller
Bundle a Runner JAR and pass its extracted path to BarCodeReader:
# Use `;runner` instead of `:runner` on Windows.
pyinstaller --add-data "/path/to/pyzxing-runner.jar:runner" app.py
import sys
from pathlib import Path
from pyzxing import BarCodeReader
bundle_dir = Path(getattr(sys, "_MEIPASS", Path(__file__).resolve().parent))
runner_jar = next((bundle_dir / "runner").glob("*.jar"))
reader = BarCodeReader(jar_path=runner_jar)
Development
./mvnw -f java-runner/pom.xml clean verify
python -m pytest tests/
Windows users can run mvnw.cmd instead of ./mvnw.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyzxing-1.2.1.tar.gz.
File metadata
- Download URL: pyzxing-1.2.1.tar.gz
- Upload date:
- Size: 638.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72612f347bfeecefc34a9e76c0582816d47a354041b3bb6dadad884a5d32943f
|
|
| MD5 |
377e6ece1937f605f457e7bfed887a97
|
|
| BLAKE2b-256 |
c9ead447fa5e302d0da05f0501501c3f5044eefd5daf4bc56f3715b8f326ebad
|
Provenance
The following attestation bundles were made for pyzxing-1.2.1.tar.gz:
Publisher:
ci-cd.yml on ChenjieXu/pyzxing
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyzxing-1.2.1.tar.gz -
Subject digest:
72612f347bfeecefc34a9e76c0582816d47a354041b3bb6dadad884a5d32943f - Sigstore transparency entry: 2187053839
- Sigstore integration time:
-
Permalink:
ChenjieXu/pyzxing@83c2ac3dccb316e624c19cbbcf7017c381e4a4d5 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/ChenjieXu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci-cd.yml@83c2ac3dccb316e624c19cbbcf7017c381e4a4d5 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file pyzxing-1.2.1-py3-none-any.whl.
File metadata
- Download URL: pyzxing-1.2.1-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5abb96baa12908c680c02dbd12c5ca4f5f188dca3d0ff487c23e8847a717623
|
|
| MD5 |
4b3592157f847cb8f83444ea4889cd49
|
|
| BLAKE2b-256 |
3fbd797260b1aa9475155576a4c44acd492584a595506958e19758da162339fc
|
Provenance
The following attestation bundles were made for pyzxing-1.2.1-py3-none-any.whl:
Publisher:
ci-cd.yml on ChenjieXu/pyzxing
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyzxing-1.2.1-py3-none-any.whl -
Subject digest:
a5abb96baa12908c680c02dbd12c5ca4f5f188dca3d0ff487c23e8847a717623 - Sigstore transparency entry: 2187053852
- Sigstore integration time:
-
Permalink:
ChenjieXu/pyzxing@83c2ac3dccb316e624c19cbbcf7017c381e4a4d5 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/ChenjieXu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci-cd.yml@83c2ac3dccb316e624c19cbbcf7017c381e4a4d5 -
Trigger Event:
workflow_dispatch
-
Statement type: