Machine readable zone generator and checker for passports, visas, id cards and other travel documents
Project description
MRZ Generator & MRZ Checker
Description:
Machine Readable Zone generator and checker for official travel documents sizes 1, 2, 3, MRVA and MRVB (Passports, Visas, national id cards and other travel documents)
MRZ Generator and MRZ Checker are built according to International Civil Aviation Organization specifications (ICAO 9303):
- Specifications Common to all Machine Readable Travel Documents (MRTDs)
- Specifications for Machine Readable Passports (MRPs)
- Specifications for TD1 Size Machine Readable Official Travel Documents (MROTDs)
- Specifications for TD2 Size Machine Readable Official Travel Documents (MROTDs)
- Specifications for Machine Readable Visas (MRV)
See all 9303 ICAO docs (البيت العربي, 中文, English, Français, Русский and Español)
Fields Distribution of Official Travel Documents:
Usage Generator:
TD1's (id cards):
Params: Case insensitive
document_type (str): The first letter shall be 'I', 'A' or 'C'
country_code (str): 3 letters code (ISO 3166-1) or country name (in English)
document_number (str): Document number
birth_date (str): YYMMDD
sex (str): Genre. Male: 'M', Female: 'F' or Undefined: 'X', "<" or ""
expiry_date (str): YYMMDD
nationality (str): 3 letters code (ISO 3166-1) or country name (in English)
surname (str): Holder primary identifier(s). This field will be transliterated
given_names (str): Holder secondary identifier(s). This field will be transliterated
optional_data1 (str): Optional personal data at the discretion of the issuing State.
Non-mandatory field. Empty string by default
optional_data2 (str): Optional personal data at the discretion of the issuing State.
Non-mandatory field. Empty string by default
transliteration (dict): Transliteration dictionary for non-ascii chars. Latin based by default
force (bool): Disables checks for country, nationality and document_type fields.
Allows to use 3-letter-codes not included in the countries dictionary
and to use document_type codes without restrictions.
TD2
Params: Case insensitive
document_type (str): The first letter shall be 'I', 'A' or 'C'
country_code (str): 3 letters code (ISO 3166-1) or country name (in English)
surname (str): Holder primary identifier(s). This field will be transliterated.
given_names (str): Holder secondary identifier(s). This field will be transliterated.
document_number (str): Document number.
nationality (str): 3 letters code (ISO 3166-1) or country name
birth_date (str): YYMMDD
sex (str): Genre. Male: 'M', Female: 'F' or Undefined: 'X', "<" or ""
expiry_date (str): YYMMDD
optional_data (str): Optional personal data at the discretion of the issuing State.
Non-mandatory field. Empty string by default
transliteration (dict): Transliteration dictionary for non-ascii chars. Latin based by default
force (bool): Disables checks for country, nationality and document_type fields.
Allows to use 3-letter-codes not included in the countries dictionary
and to use document_type codes without restrictions.
TD3 (Passports)
Params: Case insensitive
document_type (str): Normally 'P' for passport
country_code (str): 3 letters code (ISO 3166-1) or country name (in English)
surname (str): Primary identifier(s)
given_names (str): Secondary identifier(s)
document_number (str): Document number
nationality (str): 3 letters code (ISO 3166-1) or country name
birth_date (str): YYMMDD
sex (str): Genre. Male: 'M', Female: 'F' or Undefined: 'X', "<" or ""
expiry_date (str): YYMMDD
optional data (str): Personal number. In some countries non-mandatory field. Empty string by default
transliteration (dict): Transliteration dictionary for non-ascii chars. Latin based by default
force (bool): Disables checks for country, nationality and document_type fields.
Allows to use 3-letter-codes not included in the countries dictionary
and to use document_type codes without restrictions.
MRVA (Visas type A)
Params: Case insensitive
document_type (str): The First letter must be 'V'
country_code (str): 3 letters code (ISO 3166-1) or country name (in English)
surname (str): Primary identifier(s)
given_names (str): Secondary identifier(s)
document_number (str): Document number
nationality (str): 3 letters code (ISO 3166-1) or country name
birth_date (str): YYMMDD
sex (str): Genre. Male: 'M', Female: 'F' or Undefined: 'X', "<" or ""
expiry_date (str): YYMMDD
optional_data (str): Optional personal data at the discretion of the issuing State.
Non-mandatory field. Empty string by default.
transliteration (dict): Transliteration dictionary for non-ascii chars. Latin based by default
force (bool): Disables checks for country, nationality and document_type fields.
Allows to use 3-letter-codes not included in the countries dictionary
and to use document_type codes without restrictions.
MRVB (Visas type B)
Params: Case insensitive
document_type (str): The First letter must be 'V'
country_code (str): 3 letters code (ISO 3166-1) or country name (in English)
surname (str): Primary identifier(s)
given_names (str): Secondary identifier(s)
document_number (str): Document number
nationality (str): 3 letters code (ISO 3166-1) or country name
birth_date (str): YYMMDD
sex (str): Genre. Male: 'M', Female: 'F' or Undefined: 'X', "<" or ""
expiry_date (str): YYMMDD
optional_data (str): Optional personal data at the discretion of the issuing State.
Non-mandatory field. Empty string by default.
transliteration (dict): Transliteration dictionary for non-ascii chars. Latin based by default
force (bool): Disables checks for country, nationality and document_type fields.
Allows to use 3-letter-codes not included in the countries dictionary
and to use document_type codes without restrictions.
Passport generator example (ICAO9303 Specimen):
TD3CodeGenerator -> str:
from mrz.generator.td3 import TD3CodeGenerator
code = TD3CodeGenerator("P", "UTO", "Eriksson", "Anna María", "L898902C3", "UTO", "740812", "F", "120415","ZE184226B")
print(code)
Output:
P<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<
L898902C36UTO7408122F1204159ZE184226B<<<<<10
Note: See other uses in mrz.generator examples folder
Usage Checker:
TD1's (id cards):
Params:
mrz_string (str): MRZ string of TD1. Must be 90 uppercase characters long (3 lines)
check_expiry (bool): If it's set to True, it is verified and reported as warning that the
document is not expired and that expiry_date is not greater than 10 years
compute_warnings (bool): If it's set True, warnings compute as False
TD2:
Params:
mrz_string (str): MRZ string of TD2. Must be 72 characters long (uppercase) (2 lines)
check_expiry (bool): If it's set to True, it is verified and reported as warning that the
document is not expired and that expiry_date is not greater than 10 years
compute_warnings (bool): If it's set True, warnings compute as False
TD3 (Passports):
Params:
mrz_string (str): MRZ string of TD3. Must be 88 characters long (uppercase) (2 lines)
check_expiry (bool): If it's set to True, it is verified and reported as warning that the
document is not expired and that expiry_date is not greater than 10 years
compute_warnings (bool): If it's set True, warnings compute as False
MRVA:
Params:
mrz_string (str): MRZ string of Visas type A. Must be 88 characters long (uppercase) (2 lines)
check_expiry (bool): If it's set to True, it is verified and reported as warning that the
document is not expired and that expiry_date is not greater than 10 years
compute_warnings (bool): If it's set True, warnings compute as False
MRVB:
Params:
mrz_string (str): MRZ string of Visas type B. Must be 72 characters long (uppercase) (2 lines)
check_expiry (bool): If it's set to True, it is verified and reported as warning that the
document is not expired and that expiry_date is not greater than 10 years
compute_warnings (bool): If it's set True, warnings compute as False
Id Card Checker example
TD1CodeChecker -> bool
from mrz.checker.td1 import TD1CodeChecker
check = TD1CodeChecker("I<SWE59000002<8198703142391<<<\n"
"8703145M1701027SWE<<<<<<<<<<<8\n"
"SPECIMEN<<SVEN<<<<<<<<<<<<<<<<")
result = bool(check)
print(result)
Output
True
Note: See other uses in mrz.checker examples folder
Fields extraction example (valid for td1, td2, td3 and visas)
from mrz.checker.td1 import TD1CodeChecker, get_country
td1_check = TD1CodeChecker("IDLIEID98754015<<<<<<<<<<<<<<<\n"
"8205122M1906224LIE<<<<<<<<<<<6\n"
"OSPELT<BECK<<MARISA<<<<<<<<<<<")
fields = td1_check.fields()
print(fields.name, fields.surname)
print(get_country(fields.country))
Output
MARISA OSPELT BECK
Liechtenstein
Note: See other uses in mrz.checker examples folder and this issue
Installation:
From Pypi repo (It may not be the latest version):
pip install mrz
Cloning this repo (It may not work fine):
git clone https://github.com/Arg0s1080/mrz.git
cd mrz
sudo python3 setup.py install
Features:
- Transliteration of special Latin characters (acutes, tildes, diaeresis, graves, circumflex, etc)
- Arabic chars transliteration
- Several variations of Cyrillic added: Serbian, Macedonian, Belarusian, Ukrainian and Bulgarian
- Transliteration of modern Greek (experimental)
- Transliteration of modern Hebrew (without vowels) (experimental)
- Generation of the country code from its name in English (Ex.: "Netherlands" -> "NLD")
- Name truncation detection
- Error report, warnings report and full report in Checker.
- Possibility that warnings compute as errors using compute_warnings keyword in Checker.
- Possibility of disabling checks for country code, nationality and type of document, allowing to use 3-letter-codes not included in the countries dictionary and to use document_type codes without restrictions in Generator.
- Added new checks for periods of time in Checker.
- Visas support
- Fields extraction in checker (name, surname, country, sex, etc) (version 0.5.0)
TODO:
- Automatic name truncation in Generator
- Possibility of disabling checks for country code, nationality, type of document and the others fields in Checker.
- Add logging
IMPORTANT:
-
MRZ is a Python module to be used as library in other programs. So, its intended audience are developers. MRZ will never have a user interface nor will have CLI support. (Of course.. if someone wants, can do it) However, if someone is curious and wants to generate or check the mrz code of a passport or ID card, can modify any of the examples.
-
Right now I am very busy and have very little free time. Please, before creating an issue or consulting by email, read this issue
Uploading to PyPi
- Remove existing directories
rm -r build dist
- Build
python3 setup.py sdist bdist_wheel
- Upload to PyPi
twine upload --verbose dist/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mrz-surepass-0.6.4.tar.gz
.
File metadata
- Download URL: mrz-surepass-0.6.4.tar.gz
- Upload date:
- Size: 46.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c58a0270b0a1110c12a5f93b0d05a9dd990f9f81591ed5b0fa80aa568459c2b0 |
|
MD5 | 38bf0a440d7753a9e756192dabe88b45 |
|
BLAKE2b-256 | 134ce141ae16064ec6f8edca284d21da6b73832bb611ab8076bfe92b8796ed39 |
File details
Details for the file mrz_surepass-0.6.4-py3-none-any.whl
.
File metadata
- Download URL: mrz_surepass-0.6.4-py3-none-any.whl
- Upload date:
- Size: 73.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f3a95d66b38a6bb7674ece39d83c594b90de759a7ce7709213ccf189613bd07 |
|
MD5 | 6343d756d9d7d4a4f7fdb9557593cc80 |
|
BLAKE2b-256 | b0bfece2a73ac1f055cf271eeb501f28c464232fef718c13afd357c089dca40f |