Skip to main content

Machine readable zone generator and checker for passports, visas, id cards and other travel documents

Project description

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):

See all 9303 ICAO docs (Arab, Chinese, English, French, Russian and Spanish)

Fields Distribution of Official Travel Documents:

image

image

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):

image

image

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

image

image

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:

  • [x] Transliteration of special Latin characters (acutes, tildes, diaeresis, graves, circumflex, etc)

  • [x] Arabic chars transliteration

  • [x] Several variations of Cyrillic added: Serbian, Macedonian, Belarusian, Ukrainian and Bulgarian

  • [x] Transliteration of modern Greek (experimental)

  • [x] Transliteration of modern Hebrew (without vowels) (experimental)

  • [x] Generation of the country code from its name in English (Ex.: “Netherlands” -> “NLD”)

  • [x] Name truncation detection

  • [x] Error report, warnings report and full report in Checker.

  • [x] Possibility that warnings compute as errors using compute_warnings keyword in Checker.

  • [x] 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.

  • [x] Added new checks for periods of time in Checker.

  • [x] Visas support

  • [x] 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mrz-0.5.8.tar.gz (29.3 kB view details)

Uploaded Source

Built Distribution

mrz-0.5.8-py3-none-any.whl (59.4 kB view details)

Uploaded Python 3

File details

Details for the file mrz-0.5.8.tar.gz.

File metadata

  • Download URL: mrz-0.5.8.tar.gz
  • Upload date:
  • Size: 29.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.10.0 pkginfo/1.2.1 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.9

File hashes

Hashes for mrz-0.5.8.tar.gz
Algorithm Hash digest
SHA256 a312526c119b3d6c280e8b669adc1bbb41837f379ac3622bbb7dfa7a94f6c9a3
MD5 9645a5fc38203f479b3b9e079bf8f81b
BLAKE2b-256 1f9e978952331f8be533a96b511c204960f032e62d997845a7b54d7e2c918ded

See more details on using hashes here.

File details

Details for the file mrz-0.5.8-py3-none-any.whl.

File metadata

  • Download URL: mrz-0.5.8-py3-none-any.whl
  • Upload date:
  • Size: 59.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.10.0 pkginfo/1.2.1 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.9

File hashes

Hashes for mrz-0.5.8-py3-none-any.whl
Algorithm Hash digest
SHA256 be6eed6014f082db33a0dedee12f5c434209918bc5730acf118536998052760b
MD5 ad0d71e44249749bdddf47dac18cc255
BLAKE2b-256 1583395623aed451a8509ef22f920459cf49bbc8575bf8fd8692707aca7d1f62

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page