pharmacode-toolkit
Generate, detect and decode one-track Pharmacode barcodes in PNG, JPEG and TIFF images. Pure Python on numpy and OpenCV.
{
"detections": [
{"bbox": {"x": 45, "y": 63, "width": 149, "height": 94}, "orientation_deg": 0.0,
"bars": ["narrow", "wide", "wide", "wide", "narrow", "narrow"],
"bar_widths_px": [3, 9, 9, 9, 3, 3],
"value": 91, "mirror_value": 77, "confidence": 1.0, "warnings": []}
],
"errors": []
}
What it does
- Encodes any value from 3 to 131070 into the 2..16 narrow/wide bars of the format.
- Renders synthetic codes with the Laetus physical dimensions at any DPI, with optional rotation, blur, noise, JPEG artefacts, contrast loss, uneven lighting, perspective and scaling, all seeded and reproducible.
- Finds one or more codes in an image at 0, 90, 180 and 270 degrees and small tilts.
- Classifies bars, checks quiet zones and geometry, and reports both reading directions, because the format has no start or stop pattern.
- Writes a JSON result with stable error codes and an annotated image.
- Ships a benchmark that reports a matrix of conditions, not one number.
Install
pip install pharmacode-toolkit
From a clone of the repository: pip install . (or pip install -e .[dev] for
development). Requires Python 3.10 or newer. Runtime dependencies: numpy,
opencv-python-headless.
Quick start
pharmacode generate --value 12345 --dpi 300 --output sample.png
pharmacode decode sample.png --dpi 300
pharmacode decode sample.png --dpi 300 --json result.json --annotated result.png
pharmacode decode sample.png --dpi 300 --min-confidence 0.8
python -m pharmacode ... works the same as the pharmacode command above,
for environments where installing a console script is inconvenient.
From Python:
from pharmacode import DecoderConfig, decode_image, load_image
result = decode_image(load_image("sample.png"), DecoderConfig(dpi=300))
for code in result.detections:
print(code.value, code.mirror_value, code.confidence)
Supported input
8-bit grayscale or colour PNG, JPEG and TIFF; dark bars on a light background;
codes upright, rotated by multiples of 90 degrees, or tilted a few degrees.
Pass --dpi whenever you know the resolution: it enables physical checks and
reliable classification of codes that use a single bar width.
Limitations
See docs/limitations.md. In short: no inverted codes, no two-track or colour Pharmacode, no DPI from file metadata. Thresholds come from the specification and a synthetic benchmark; on top of that the decoder is checked against real-world sample images (codes as they appear in the wild: with captions, tightly cropped, with a rule drawn across the bars, inside a chart of symbologies).
Documentation
Disclaimer
This project is an independent implementation from public descriptions of the format. It is not validated for regulated pharmaceutical packaging control and must not be used as the sole check in such a process.
Author
Konstantin Dotsenko (LinkedIn).
License
MIT, see LICENSE.
Metadata
Release files for pharmacode-toolkit 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pharmacode_toolkit-0.2.1.tar.gz | 339.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pharmacode_toolkit-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 374.9 kB
Release files / pharmacode_toolkit-0.2.1.tar.gz
| Download URL | pharmacode_toolkit-0.2.1.tar.gz |
|---|---|
| Size | 339.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a39419d4d72f8390542753b1cf48c4ed38c090cdca8c123ea6d7b5eac517ea14
|
|
BLAKE2b-256 checksum How to use checksums |
79d9cea3778962d3e8c5ee0736475443bb6c55aa0e97b3dd79012b2327739359
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.
Transparency logRelease files / pharmacode_toolkit-0.2.1-py3-none-any.whl
| Download URL | pharmacode_toolkit-0.2.1-py3-none-any.whl |
|---|---|
| Size | 35.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dfe159cda058bd5a8ebaee6749c2c0f0a13d778fcfc98f67095a1fabecdb7c35
|
|
BLAKE2b-256 checksum How to use checksums |
3e1111722ec1116b61d11122b24e4654e2ad87b1195af9e8e702824624c8a8cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.
Transparency log