readmrz
readmrz detects the machine readable zone on ID cards and extracts the text in that zone.
This zone contains the name, surname, date of birth, etc. of the person to whom the identity card was issued. It has universal standards in new generation identity cards and passports.
In conclusion, readmrz is a tool to read mrz code on identity cards and passports.
Install
Please install tesseract before installing the package,
On macOS,
$ brew install tesseract
On Ubuntu,
$ sudo apt-get install -y tesseract-ocr
On Windows,
$ choco install tesseract
Then you can install the latest release,
$ pip install readmrz
Usage
>>> import json
>>> from readmrz import MrzDetector, MrzReader
>>> detector = MrzDetector()
>>> reader = MrzReader()
>>> image = detector.read('/path/to/file')
>>> cropped = detector.crop_area(image)
>>> result = reader.process(cropped)
>>> print(json.dumps(result))
{
"surname": "STEARNE",
"name": "JOHN TIMOTHY KELLY",
"country": "CAN",
"nationality": "CAN",
"birth_date": "580702",
"expiry_date": "240904",
"sex": "M",
"document_type": "P",
"document_number": "GA302922",
"optional_data": "",
"birth_date_hash": "0",
"expiry_date_hash": "3",
"document_number_hash": "0",
"final_hash": "2"
}
or using url,
>>> import json
>>> from readmrz import MrzDetector, MrzReader
>>> detector = MrzDetector()
>>> reader = MrzReader()
>>> image = detector.read_from_url('/url/to/image')
>>> cropped = detector.crop_area(image)
>>> result = reader.process(cropped)
>>> print(json.dumps(result))
{
"surname": "STEARNE",
"name": "JOHN TIMOTHY KELLY",
"country": "CAN",
"nationality": "CAN",
"birth_date": "580702",
"expiry_date": "240904",
"sex": "M",
"document_type": "P",
"document_number": "GA302922",
"optional_data": "",
"birth_date_hash": "0",
"expiry_date_hash": "3",
"document_number_hash": "0",
"final_hash": "2"
}
The result is returned as a dict so it's easy to access the fields. You can also use command-line,
$ readmrz -f /path/to/file
or using url,
$ readmrz -u /url/to/image
Example
Please check to the notebook to see the results step by step.
Contribution
Please check to the pylint and flake8 steps in workflow before contribution.
Metadata
Release files for readmrz 0.0.2
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 |
|---|---|---|---|---|
| readmrz-0.0.2.tar.gz | 10.9 MB | Without provenance | Details for readmrz-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| readmrz-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for readmrz-0.0.2-py3-none-any.whl |
Total release size: 21.9 MB
Release files / readmrz-0.0.2.tar.gz
| Download URL | readmrz-0.0.2.tar.gz |
|---|---|
| Size | 10.9 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
db984bb73932487f188ab1b716b509ec93f2d768d9997cdf143fe32ecad10805
|
|
BLAKE2b-256 checksum How to use checksums |
71577c66058bc998d05ead16d3700cc4bc63a8a69500413481d2a07a8678453f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.8
|
Release files / readmrz-0.0.2-py3-none-any.whl
| Download URL | readmrz-0.0.2-py3-none-any.whl |
|---|---|
| Size | 10.9 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cbdc5d6b630518f903b8de45ca3efabcfe8ad25ce62059b5c11a392872097726
|
|
BLAKE2b-256 checksum How to use checksums |
b8b41053f99b61305c2a53d148d19765bf0b0ea2a1e98c6e284f26a1e0f7c2a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.8
|
Security for readmrz 0.0.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.