Skip to main content

Python Versions PyPI version Travis status Coverage Status

A ctypes-based Python wrapper around the zbar barcode reader.

The zbar wrapper is stuck in Python 2.x-land. The zbarlight wrapper doesn’t provide support for Windows and depends upon Pillow. This ctypes-based wrapper brings zbar to Python 2.7 and to Python 3.4 or greater.

Installation

The zbar DLLs are included with the Windows Python wheels. On other operating systems, you will need to install the zbar shared library.

On Mac OS X:

brew install zbar

On Linux:

sudo apt-get install libzbar0

Install this Python wrapper; use the second form to install dependencies of the command-line scripts:

pip install pyzbar
pip install pyzbar[scripts]

Example usage

The decode function accepts instances of PIL.Image.

>>> from pyzbar.pyzbar import decode
>>> from PIL import Image
>>> decode(Image.open('pyzbar/tests/code128.png'))
[Decoded(data=b'Foramenifera', type='CODE128'),
 Decoded(data=b'Rana temporaria', type='CODE128')]

It also accepts instances of numpy.ndarray, which might come from loading images using OpenCV.

>>> import cv2
>>> decode(cv2.imread('pyzbar/tests/code128.png'))
[Decoded(data=b'Foramenifera', type='CODE128'),
 Decoded(data=b'Rana temporaria', type='CODE128')]

You can also provide a tuple (pixels, width, height), where the image data is eight bits-per-pixel.

>>> image = cv2.imread('pyzbar/tests/code128.png')
>>> height, width = image.shape[:2]

>>> # 8 bpp by considering just the blue channel
>>> decode((image[:, :, 0].astype('uint8').tobytes(), width, height))
[Decoded(data=b'Foramenifera', type='CODE128'),
 Decoded(data=b'Rana temporaria', type='CODE128')]

>>> # 8 bpp by converting image to greyscale
>>> grey = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
>>> decode((grey.tobytes(), width, height))
[Decoded(data=b'Foramenifera', type='CODE128'),
 Decoded(data=b'Rana temporaria', type='CODE128')]

>>> # If you don't provide 8 bpp
>>> decode((image.tobytes(), width, height))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/lawh/projects/pyzbar/pyzbar/pyzbar.py", line 102, in decode
    raise PyZbarError('Unsupported bits-per-pixel [{0}]'.format(bpp))
pyzbar.pyzbar_error.PyZbarError: Unsupported bits-per-pixel [24]

zbar’s default behaviour is (I think) to decode all symbol types. You can ask zbar to look for just your symbol types (I have no idea of the effect of this on performance)

>>> from pyzbar.pyzbar import ZBarSymbol
>>> # Look for just qrcode
>>> decode(Image.open('pyzbar/tests/qrcode.png'), symbols=[ZBarSymbol.QRCODE])
[Decoded(data=b'Thalassiodracon', type='QRCODE')]

>>> # If we look for just code128, the qrcodes in the image will not be detected
>>> decode(Image.open('pyzbar/tests/qrcode.png'), symbols=[ZBarSymbol.CODE128])
[]

License

pyzbar is distributed under the MIT license (see LICENCE.txt). The zbar shared library is distributed under the GNU Lesser General Public License, version 2.1 (see zbar-LICENCE.txt).

Metadata

Release files for pyzbar 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for pyzbar 0.1.4
File Interpreter ABI Platform
pyzbar-0.1.4-py2.py3-none-win_amd64.whl Python 3, Python 2 none Windows x86-64 Details
pyzbar-0.1.4-py2.py3-none-win32.whl Python 2, Python 3 none Windows x86-32 Details
pyzbar-0.1.4-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 2.4 MB

Release files / pyzbar-0.1.4-py2.py3-none-win_amd64.whl

Download URL pyzbar-0.1.4-py2.py3-none-win_amd64.whl
Size 1.6 MB
Tags Python 2 Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
1ccf12c8421de54a6fe2f6ed6aba21810ae1ff2724eb33205bdf62b190eac7ce
BLAKE2b-256 checksum
How to use checksums
f96a90ea5456a526389d7333eae610b700ac747a8c31b4a9bcd8fd362a3d3c05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pyzbar-0.1.4-py2.py3-none-win32.whl

Download URL pyzbar-0.1.4-py2.py3-none-win32.whl
Size 800.1 kB
Tags Python 2 Python 3 Windows x86-32
SHA-256 checksum
How to use checksums
8bd6a81968dbd9f786c5a0075b53eef29d95c6b2a6aba9a5e4a61ad41bc960de
BLAKE2b-256 checksum
How to use checksums
d834b63a1746bac0733052a1eb2850734cf5ead8ff5059bd35b9a3b76a19a465
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pyzbar-0.1.4-py2.py3-none-any.whl

Download URL pyzbar-0.1.4-py2.py3-none-any.whl
Size 22.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
1e690ee6cd40ef352caf930c1733234ee978560331828cd7208f2eedbbb9fdb7
BLAKE2b-256 checksum
How to use checksums
391f5ccd468ce5c3cc500f83d4b8d8dbf09266010639375562ee41de702c6974
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.1.9

3 release files

0.1.8

3 release files

0.1.7

3 release files

0.1.5

3 release files

This release

0.1.4 This release

3 release files

0.1.3

3 release files

0.1.2

3 release files

0.1.1

3 release files

0.1.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page