Skip to main content
https://img.shields.io/badge/python-2.7%2C%203.4%2C%203.5%2C%203.6%2C%203.7-blue.svg https://badge.fury.io/py/pylibdmtx.svg https://travis-ci.org/NaturalHistoryMuseum/pylibdmtx.svg?branch=master https://coveralls.io/repos/github/NaturalHistoryMuseum/pylibdmtx/badge.svg?branch=master

Read and write Data Matrix barcodes from Python 2 and 3 using the libdmtx library.

  • Pure python

  • Works with PIL / Pillow images, OpenCV / numpy ndarrays, and raw bytes

  • Decodes locations of barcodes

  • No dependencies, other than the libdmtx library itself

  • Tested on Python 2.7, and Python 3.4 to 3.7

The older pydmtx package is stuck in Python 2.x-land.

Installation

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

Mac OS X:

brew install libdmtx

Linux:

sudo apt-get install libdmtx0a

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

pip install pylibdmtx
pip install pylibdmtx[scripts]

Example usage

The decode function accepts instances of PIL.Image.

>>> from pylibdmtx.pylibdmtx import decode
>>> from PIL import Image
>>> decode(Image.open('pylibdmtx/tests/datamatrix.png'))
[Decoded(data='Stegosaurus', rect=Rect(left=5, top=6, width=96, height=95)),
 Decoded(data='Plesiosaurus', rect=Rect(left=298, top=6, width=95, height=95))]

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

>>> import cv2
>>> decode(cv2.imread('pylibdmtx/tests/datamatrix.png'))
[Decoded(data='Stegosaurus', rect=Rect(left=5, top=6, width=96, height=95)),
 Decoded(data='Plesiosaurus', rect=Rect(left=298, top=6, width=95, height=95))]

You can also provide a tuple (pixels, width, height)

>>> image = cv2.imread('pylibdmtx/tests/datamatrix.png')
>>> height, width = image.shape[:2]
>>> decode((image.tobytes(), width, height))
[Decoded(data='Stegosaurus', rect=Rect(left=5, top=6, width=96, height=95)),
 Decoded(data='Plesiosaurus', rect=Rect(left=298, top=6, width=95, height=95))]

The encode function generates an image containing a Data Matrix barcode:

>>> from pylibdmtx.pylibdmtx import encode
>>> encoded = encode('hello world')
>>> img = Image.frombytes('RGB', (encoded.width, encoded.height), encoded.pixels)
>>> img.save('dmtx.png')

Windows error message

If you see an ugly ImportError when importing pylibdmtx on Windows you will most likely need the Visual C++ Redistributable Packages for Visual Studio 2013. Install vcredist_x64.exe if using 64-bit Python, vcredist_x86.exe if using 32-bit Python.

Limitations

Feel free to submit a PR to address any of these.

  • I took the bone-headed approach of copying the logic in pydmtx’s decode function (in pydmtxmodule.c); there might be more of libdmtx’s functionality that could usefully be exposed

  • I exposed the bare minimum of functions, defines, enums and typedefs neede to reimplement pydmtx’s decode function

Contributors

  • Vinicius Kursancew (@kursancew) - first implementation of barcode writing

  • Joseph Weston (@jbweston) - support for libdmtx 0.7.5

License

pylibdmtx is distributed under the MIT license (see LICENCE.txt). The libdmtx shared library is distributed under the Simplified BSD license (see libdmtx-LICENCE.txt).

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pylibdmtx-0.1.8-py2.py3-none-win_amd64.whl (65.4 kB view details)

Uploaded Python 2Python 3Windows x86-64

pylibdmtx-0.1.8-py2.py3-none-win32.whl (57.7 kB view details)

Uploaded Python 2Python 3Windows x86

pylibdmtx-0.1.8-py2.py3-none-any.whl (22.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pylibdmtx-0.1.8-py2.py3-none-win_amd64.whl.

File metadata

  • Download URL: pylibdmtx-0.1.8-py2.py3-none-win_amd64.whl
  • Upload date:
  • Size: 65.4 kB
  • Tags: Python 2, Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for pylibdmtx-0.1.8-py2.py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 4c7314f7ca7c29147cd32053f102f9fc20473923498417654e4ba91580cf6c1d
MD5 f1812d1b0193d38a64de6e7b0c643aaa
BLAKE2b-256 3ad4cbe999fbfad0c6ab5fb4e0d5e78ce14d2af68279011ed679283c50d6a0dd

See more details on using hashes here.

File details

Details for the file pylibdmtx-0.1.8-py2.py3-none-win32.whl.

File metadata

  • Download URL: pylibdmtx-0.1.8-py2.py3-none-win32.whl
  • Upload date:
  • Size: 57.7 kB
  • Tags: Python 2, Python 3, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for pylibdmtx-0.1.8-py2.py3-none-win32.whl
Algorithm Hash digest
SHA256 2617660ab240bc77e3ceab546c1f5ec8b4bcca7f7f181695d95a5b98555509ef
MD5 ded43f98954ffd8f45f4d26a52b8d56b
BLAKE2b-256 18b1b2bd69b5a14279de1e3e1197094dc394743252c55ebb524b4ba352fc00c1

See more details on using hashes here.

File details

Details for the file pylibdmtx-0.1.8-py2.py3-none-any.whl.

File metadata

  • Download URL: pylibdmtx-0.1.8-py2.py3-none-any.whl
  • Upload date:
  • Size: 22.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for pylibdmtx-0.1.8-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 7bc127b94a6e2ff6dc09cb69d66602302f490bec83fcea14ab3a8e55dd407a50
MD5 04029a2f22d7780b776f5b0171478584
BLAKE2b-256 608219bffdee05154cfd5eece79c09b7d1ddf41b6bcd66f781a9cd0fdd348ee0

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.10

3 files

0.1.9

3 files

This release

0.1.8 This release

3 files

0.1.7

3 files

0.1.6

3 files

0.1.5

3 files

0.1.4

3 files

0.1.3

3 files

0.1.2

3 files

0.1.1

3 files

0.1.0

3 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