mrzmini
mrzmini finds and reads the MRZ (machine-readable zone) of ID documents. It uses the algorithm of PassportEye. It has only two Python dependencies: numpy and Pillow.
Install
pip install mrzmini
You must have Python 3.12 or later.
Install the tesseract binary on PATH:
apt install tesseract-ocr # Debian/Ubuntu
brew install tesseract # macOS
To use a different binary, set TESSERACT_CMD.
Usage
from mrzmini import read_mrz
mrz = read_mrz('passport.jpg') # path, bytes, file object, PDF, PIL image or numpy array
print(mrz.to_dict()) # mrz is None if there is no MRZ
mrzmini passport.jpg
read_mrz has the same interface and the same MRZ fields as in PassportEye.
mrzmini adds the lang argument and images in memory.
Tesseract model
By default, tesseract uses its default model (eng). To change the model, use lang:
read_mrz('passport.jpg', lang='mrz') # or 'eng', 'mrz+eng'
read_mrz('passport.jpg', lang='auto') # 'mrz' if installed, else the default
Tesseract does not supply mrz. Put an mrz.traineddata file in the tessdata directory.
The environment variable MRZMINI_TESSERACT_LANG sets lang for all reads.
Then the results can be different from PassportEye.
Detailed result
read_mrz_detailed always returns an MRZResult, also if there is no MRZ:
from mrzmini import ROTATED_VIEWS, read_mrz_detailed
result = read_mrz_detailed(page, lang='auto')
result.mrz # the best read: an MRZ or None
result.accepted # accept(mrz), or mrz.valid without accept
result.view # the view of the read, for example (0, 250)
result.ocr_calls # number of OCR calls
result.elapsed_s # duration, in seconds
result.budget_exhausted # True if a limit stopped the read
All the arguments after file are keywords. Without options, the result is the same as read_mrz.
| Argument | Effect |
|---|---|
accept |
A function MRZ -> bool. It replaces mrz.valid as the stop condition. |
max_ocr_calls |
The maximum number of OCR calls. |
deadline |
A time.monotonic() instant. No step starts after it. |
views |
More views to examine if the normal read finds no accepted MRZ. Use ROTATED_VIEWS for pages turned by 90°. |
pass1 |
False skips the normal read. Use it with views. |
rank_key |
A function MRZ -> key. It replaces valid_score to select the best read. |
keep_candidates |
True keeps all the reads in result.candidates, best first. |
When a limit stops the read, there is no exception. The result is the best read before the limit.
The steps without OCR cannot stop. Thus a read can end some tenths of a second after deadline.
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 read this format.
CNI_FR
expiration_dateisNone. This MRZ has no expiry date.valid_check_digitsis[number, date_of_birth, composite]. Index 2 is not the expiry date. Usevalid_number,valid_date_of_birthandvalid_composite.issue_dateisYYMM.administrative_codehas 6 characters.detection_modeis'prefix','shifted'or'line2'.surname_truncatedandnames_truncatedareTrueif the field is full. Then the name can be cut. They areNoneif the positions are not reliable (not'prefix'mode with 2 lines of 36 characters).
mrzmini does not repair the lines. A line that does not have 36 characters is not valid.
Only read_mrz and MRZ.from_ocr find CNI_FR. MRZ(lines) does not.
To test lines that you split yourself, use looks_like_cni_fr(lines).
Differences from PassportEye
parity_check.py compares mrzmini with PassportEye on the 36 test images of PassportEye.
The valid ICAO reads are the same. There are two differences:
- mrzmini can read an invalid MRZ as
CNI_FR, with a differentvalid_score. - When PassportEye gives no
method, mrzmini givesmethod='direct'.
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.
- The check digits use modulo 10. Some misreads pass all the checks, for example
<read asK.
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.3.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 | Provenance | Actions |
|---|---|---|---|---|
| mrzmini-0.3.1.tar.gz | 41.7 kB | With provenance | Details for mrzmini-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mrzmini-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for mrzmini-0.3.1-py3-none-any.whl |
Total release size: 87.0 kB
Release files / mrzmini-0.3.1.tar.gz
| Download URL | mrzmini-0.3.1.tar.gz |
|---|---|
| Size | 41.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c5a3f61766c0d60b8adc9592dcb145ec5a7b281ed2a6784a91f1306bad501021
|
|
BLAKE2b-256 checksum How to use checksums |
602b461971417c5a3710160e68f64c56752d75aeee44aa2aad994fc3d175a0af
|
| 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 30, 2026.
Transparency logRelease files / mrzmini-0.3.1-py3-none-any.whl
| Download URL | mrzmini-0.3.1-py3-none-any.whl |
|---|---|
| Size | 45.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a79c847c5586fae0b0006cfbc503576e1f1999a16ae4f55c3887a79c2031c8c5
|
|
BLAKE2b-256 checksum How to use checksums |
002a7992016a5a935739244e2cd7eff33dc09bab9d708cd29f05b925ec78b7cb
|
| 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 30, 2026.
Transparency logSecurity for mrzmini 0.3.1
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.
Attestation for mrzmini-0.3.1.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 30, 2026.
Transparency logA 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.