Skip to main content

barcodekit

日本語

barcodekit generates barcode PNG images from Python by invoking the local barcode-rest executable in its one-shot CLI mode.

Despite the upstream executable's name, barcodekit's default mode does not start the REST server and does not use HTTP. Each default-mode operation runs only:

barcode-rest generate <symbology> --text <text> --output -

PNG bytes are read from standard output and returned directly to Python.

For bulk generation, BarcodeKit(server=True) can opt in to a local resident server. This starts the bundled barcode-rest process on 127.0.0.1 for the life of the context manager, passes a generated -exit-token, and sends requests to that local process only.

Quick start

Install the platform-specific wheel, then:

from barcodekit import code128, datamatrix, qr

datamatrix("ABC123", size=256).save("dm.png")
qr("https://example.com", size=512, level="Q").save("qr.png")
code128("ABC-123456", label=True).save("c128.png")

An explicit engine object provides the same methods:

from barcodekit import BarcodeKit

kit = BarcodeKit(timeout=10)
image = kit.datamatrix("ABC123", size=256)

raw_png = image.to_bytes()
image.save("dm.png")

For many images, use server mode to avoid starting a new process for every barcode:

from barcodekit import barcodekit

with barcodekit(server=True) as kit:
    for index in range(1000):
        kit.datamatrix(f"ITEM-{index:04d}", size=256).save(f"dm-{index:04d}.png")

The class form is equivalent:

from barcodekit import BarcodeKit

with BarcodeKit(server=True) as kit:
    image = kit.qr("https://example.com")

Parallel bulk generation

Resident server mode can generate independent images concurrently. Results from generate_many() remain in the same order as the input values:

from barcodekit import barcodekit

values = [f"ITEM-{index:06d}" for index in range(10_000)]

with barcodekit(server=True) as kit:
    images = kit.generate_many("datamatrix", values, workers=8, size=256)

For large or streaming inputs, imap() keeps at most twice the configured worker count queued and yields images in input order:

with barcodekit(server=True) as kit:
    for index, image in enumerate(
        kit.imap("qr", values, workers=8, size=256, level="M")
    ):
        image.save(f"qr-{index:06d}.png")

Fully consuming the iterator releases its worker pool automatically. If you may stop early, close the iterator explicitly; contextlib.closing() does so even when the loop exits with break or an exception:

from contextlib import closing

with barcodekit(server=True) as kit:
    images = kit.imap("qr", values, workers=8, size=256, level="M")
    with closing(images):
        for index, image in enumerate(images):
            image.save(f"qr-{index:06d}.png")
            if index + 1 >= 100:
                break

Parallel generation requires server=True. If workers is omitted, barcodekit uses the detected CPU count, capped at 8. More workers are not always faster, so benchmark the intended barcode type and host. If an item fails, BarcodeKitBatchError.index identifies its zero-based input position without including the input text in the error message.

For datamatrix, qr, and aztec, size and module are mutually exclusive. Set size=None when selecting the module size directly:

datamatrix("ABC123", size=None, module=8)

Using the PNG with Pillow or OpenCV

barcodekit does not depend on Pillow, OpenCV, or NumPy. If your application already uses those libraries, optional helpers can convert the returned PNG bytes:

from barcodekit import qr

pil_image = qr("ABC123").to_pillow()
from barcodekit import qr

cv_image = qr("ABC123").to_cv2()

to_pillow() requires Pillow at call time. to_cv2() requires OpenCV and NumPy at call time. These packages are not installed by barcodekit.

Executable resolution

barcodekit resolves the executable when an image is generated, in this order:

  1. The file path passed as BarcodeKit(executable=...).
  2. The file path in BARCODEKIT_BINARY.
  3. The executable bundled in the installed platform wheel.

An explicit development binary can be used without building a wheel:

kit = BarcodeKit(executable=r"C:\tools\barcode-rest.exe")
kit.datamatrix("ABC123").save("dm.png")

Or with an environment variable:

$env:BARCODEKIT_BINARY = "C:\tools\barcode-rest.exe"
uv run python example.py
BARCODEKIT_BINARY=/opt/barcode-rest uv run python example.py

These values must be file paths; barcodekit does not search PATH.

Bundled binary wheels

Each released wheel is intended to contain exactly one matching barcode-rest executable. It must not contain a collection of executables for other operating systems or CPU architectures.

Supported bundled targets:

  • Windows amd64
  • Linux amd64 using glibc 2.34 or newer, including Ubuntu 22.04 or newer
  • Linux arm64 using glibc, including 64-bit Ubuntu and 64-bit Raspberry Pi OS
  • macOS 12 or newer on Intel Macs
  • macOS 12 or newer on Apple Silicon Macs

Unsupported targets:

  • Windows arm64
  • 32-bit Linux and 32-bit Raspberry Pi OS
  • musl-based Linux distributions such as Alpine Linux

Binary-free source distributions are not intended for release. On the supported operating systems and CPU architectures listed above, development from a source checkout remains supported with BARCODEKIT_BINARY or BarcodeKit(executable=...).

Release builds currently pin barcode-rest v0.3.0. The expected SHA-256 values are committed in checksums/v0.3.0.sha256.

Supported symbologies

Two-dimensional:

  • Data Matrix (datamatrix)
  • QR Code (qr)
  • Aztec (aztec)
  • PDF417 (pdf417)

One-dimensional:

  • Code 128 (code128)
  • Code 39 (code39)
  • Code 93 (code93)
  • Codabar (codabar)
  • Interleaved 2 of 5 (itf)
  • Standard 2 of 5 (code25)
  • EAN-13 / JAN (ean13)
  • EAN-8 (ean8)

barcodekit validates supported options, numeric ranges, text limits, basic character sets, and check digits before starting the executable. Encoding constraints that depend on the generated symbol remain the responsibility of barcode-rest.

Security and privacy

  • No executable or other data is downloaded at runtime.
  • By default, no server is started and the REST API / HTTP are not used.
  • server=True starts a local barcode-rest process bound to 127.0.0.1 and uses HTTP only between Python and that local process.
  • In server mode, barcodekit starts barcode-rest with a generated -exit-token and uses it only for POST /exit when the context manager is closed.
  • No outbound network connection is made by the wrapper.
  • Barcode text is passed only to the local barcode-rest executable.
  • The wrapper does not log barcode text.
  • Commands shown by wrapper exceptions replace the value after --text with <redacted>. Matching text returned on stderr is also redacted.

In default CLI mode, the text is necessarily passed through the local process command line because that is the upstream CLI interface. It may therefore be temporarily visible to users or tools with permission to inspect local process arguments. In server=True mode, the text is sent in HTTP query strings only to the local 127.0.0.1 process; barcode-rest logs paths only and does not log query values.

Development with uv

uv sync --extra dev
uv run pytest
uv run ruff check .
uv run mypy src/barcodekit
uv build

Run the dependency-free benchmark to compare one-shot CLI generation with resident server worker counts on the current machine:

uv run python scripts/benchmark.py --count 200 --workers 1 2 4 8

The benchmark reports median batch latency, p95 batch latency, and images per second. Performance values are environment-specific and are not CI pass/fail criteria.

Unit tests mock subprocess.run and do not need the Go executable. If BARCODEKIT_BINARY is set, the optional integration test generates a real Data Matrix image and checks its PNG output.

License

barcodekit is licensed under the Apache License 2.0. Platform wheels also include the notices and license texts listed in THIRD_PARTY_NOTICES.md.

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.

barcodekit-0.2.0-py3-none-win_amd64.whl (5.4 MB view details)

Uploaded Python 3Windows x86-64

barcodekit-0.2.0-py3-none-manylinux_2_34_x86_64.whl (5.5 MB view details)

Uploaded Python 3manylinux: glibc 2.34+ x86-64

barcodekit-0.2.0-py3-none-manylinux_2_17_aarch64.whl (5.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

barcodekit-0.2.0-py3-none-macosx_12_0_x86_64.whl (5.6 MB view details)

Uploaded Python 3macOS 12.0+ x86-64

barcodekit-0.2.0-py3-none-macosx_12_0_arm64.whl (5.2 MB view details)

Uploaded Python 3macOS 12.0+ ARM64

File details

Details for the file barcodekit-0.2.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: barcodekit-0.2.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 5.4 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for barcodekit-0.2.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 6914a724da5b2afd1145ca2f4da1d4457f37f27eda760c59eab0bc1df7438356
MD5 c2d6efa7e95c9146904dbf6cb2c68202
BLAKE2b-256 1ba2a4042b5638be0114d57218a38b3b42c54f668633e34b18ea3ef132d0a01c

See more details on using hashes here.

Provenance

The following attestation bundles were made for barcodekit-0.2.0-py3-none-win_amd64.whl:

Publisher: release.yml on Moge800/barcodekit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file barcodekit-0.2.0-py3-none-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for barcodekit-0.2.0-py3-none-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 63814ddd417418f361bb81e4b70974b29b40f0cd2841755394bfff54935f0194
MD5 1c08707de3bf915822e0c9e9610e752e
BLAKE2b-256 76467335cd33228937cf78d5ea0ed95ce89e972b74dd6065d457815db9ebce77

See more details on using hashes here.

Provenance

The following attestation bundles were made for barcodekit-0.2.0-py3-none-manylinux_2_34_x86_64.whl:

Publisher: release.yml on Moge800/barcodekit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file barcodekit-0.2.0-py3-none-manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for barcodekit-0.2.0-py3-none-manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 734a79b84fd1019e9399cd4df62b7bddf45c2bcd527a71b858967f0f5a8c5f85
MD5 1722da366a5ec359920223816631a663
BLAKE2b-256 857442a739246bc952b9965d2cb695f77690a37b57bd114a718a274a855774ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for barcodekit-0.2.0-py3-none-manylinux_2_17_aarch64.whl:

Publisher: release.yml on Moge800/barcodekit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file barcodekit-0.2.0-py3-none-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for barcodekit-0.2.0-py3-none-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 b667426023406a839b8c5de4a3c02578ac709c573e6b7172b032daf0151d6564
MD5 1b1c678bd3a06f39f1884b10fadfc31b
BLAKE2b-256 109009df7399eb8fb3589dabbe045b83776158c8e5836b3ddcbcd5633e7e0145

See more details on using hashes here.

Provenance

The following attestation bundles were made for barcodekit-0.2.0-py3-none-macosx_12_0_x86_64.whl:

Publisher: release.yml on Moge800/barcodekit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file barcodekit-0.2.0-py3-none-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for barcodekit-0.2.0-py3-none-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 7cf7659e2429585d4ff70c00ae6e1c5caa8b2250a7fbb201cccaf95044e5bf13
MD5 b758b01931d5ea5067acc5abaff5ccbf
BLAKE2b-256 b204d275ed1b8cd0e527101ada6e667be2854c30cc4421cb9866da93658a45b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for barcodekit-0.2.0-py3-none-macosx_12_0_arm64.whl:

Publisher: release.yml on Moge800/barcodekit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.2.0 This release

5 files

0.1.2

3 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page