Skip to main content

mrzmini

mrzmini finds and reads the MRZ (machine-readable zone) of ID documents. It uses the same algorithm as PassportEye, but it has only two Python dependencies: numpy and Pillow.

Install

pip install mrzmini

mrzmini needs Python 3.12 or later.

For the OCR step, install the tesseract binary on PATH:

apt install tesseract-ocr   # Debian/Ubuntu
brew install tesseract      # macOS

To use a different binary, set the TESSERACT_CMD environment variable.

Usage

from mrzmini import read_mrz

mrz = read_mrz('passport.jpg')  # path, bytes, file object or PDF
print(mrz.to_dict())            # mrz is None if no MRZ is found

read_mrz(file, save_roi=False, extra_cmdline_params='') has the same interface and the same MRZ fields as in PassportEye.

Command line:

mrzmini passport.jpg

Supported formats

  • ICAO: TD1, TD2, TD3, MRVA, MRVB.
  • CNI_FR: French national ID card issued before 2021 (2 lines of 36 characters). PassportEye does not support this format.

CNI_FR fields

  • administrative_code: 6 characters (department and office).
  • issue_date: YYMM, the first 4 characters of the card number.
  • expiration_date is None. This MRZ has no expiry date.
  • valid_format is True if each character has the correct class for its position and country is 'FRA'. If it is False, valid is False.
  • valid_check_digits is [number, date_of_birth, composite]. Index 2 is the composite check, not the expiry date. Use the named attributes valid_number, valid_date_of_birth and valid_composite.
  • to_dict() does not give the expiry, optional or personal number fields.

mrzmini does not repair the lines. If a line does not have 36 characters, the MRZ is not valid.

The check digits use modulo 10. Thus, some misreads pass all checks, for example < read as K.

Only read_mrz and MRZ.from_ocr find CNI_FR. MRZ(lines) does not.

How it works

The pipeline is the same as in PassportEye:

Step What it does Upstream dependency replaced
Loader read image → grayscale (color → float64 luma, gray → uint8) skimage.io / imageio; pdfminer for PDFs
Scaler downscale so width ≤ 250 (anti-aliased) skimage.transform.rescale (→ scipy)
BooneTransform threshold_otsu(closing(|sobel_v(black_tophat(img))|)) → binary skimage.morphology + skimage.filters
MRZBoxLocator marching-squares contours → RotatedBox (PCA) → merge parallel boxes skimage.measure + sklearn.PCA
extract_from_image un-rotate + crop the ROI skimage.transform.rotate
ocr run Tesseract on the ROI pytesseract
MRZ.from_ocr clean up + parse + checksum-validate (pure Python)

Differences from PassportEye

parity_check.py compares mrzmini with PassportEye on the 36 PassportEye test images. The results are identical, with two exceptions:

  • mrzmini can give an invalid read as CNI_FR, with a different valid_score.
  • If PassportEye raises KeyError: 'method' or gives no method, mrzmini gives method='direct'.

Valid ICAO reads are always identical.

uv run --group parity python parity_check.py

Tests

uv run --group dev pytest

Limitations

  • In a PDF, mrzmini reads only the first embedded JFIF JPEG image.

License

MIT. The PassportEye algorithm and the copied modules are © Konstantin Tretyakov (MIT). The reimplemented primitives follow scikit-image and scipy (BSD).

Metadata

Release files for mrzmini 0.2.0

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

Source distribution (sdist)

Source distribution for mrzmini 0.2.0
File Size Uploaded Provenance Actions
mrzmini-0.2.0.tar.gz 30.7 kB With provenance Details for mrzmini-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mrzmini 0.2.0
File Interpreter ABI Platform Actions
mrzmini-0.2.0-py3-none-any.whl Python 3 none any Details for mrzmini-0.2.0-py3-none-any.whl

Total release size: 65.0 kB

Release files / mrzmini-0.2.0.tar.gz

Download URL mrzmini-0.2.0.tar.gz
Size 30.7 kB
Tags Source
SHA-256 checksum
How to use checksums
49c91e55b699e56c520df069df0890dbde8410a71cb0d7db2b3c758a6cfb3c97
BLAKE2b-256 checksum
How to use checksums
c77a6f95198bb79c2c80689e4f3eb10b46d4df6d2563c925eb237d0f4fcb2e8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 29, 2026.

Transparency log

Release files / mrzmini-0.2.0-py3-none-any.whl

Download URL mrzmini-0.2.0-py3-none-any.whl
Size 34.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
20e53edd775e2d921737b730954b3d38e780b113ba72ba254421f6c1654f29a3
BLAKE2b-256 checksum
How to use checksums
741f2e45ef86367a1ab695b09d773ec9ce3a1533f236dceec5cecaecd8004116
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 29, 2026.

Transparency log

Security for mrzmini 0.2.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mrzmini-0.2.0.tar.gz

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 Oct 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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