Passport data validation

 

 

Each Passport object comes with a set of validations checks. it can be accessed under the attribute Passport.checklist.

 

Example:

 

from mindee import Client

mindee_client = Client(passport_token="your_passport_token_here")

passport_data = mindee_client.parse_passport("/path/to/file")

print(passport_data.passport.checklist)

 

 

This sample code should print something like:

 

{
    'mrz_id_number_checksum': True, 
    'mrz_date_of_birth_checksum': True, 
    'mrz_expiration_date_checksum': True, 
    'mrz_personal_number_checksum': True, 
    'mrz_last_name_checksum': True, 
    'mrz_checksum': True
}

 

 

The machine readable zone includes many different checksums, allowing us to validate that the data it contains is correct. You can find more details here.

 

mrz_id_number_checksum: ID number in mrz checksum validation


mrz_date_of_birth_checksum: Date of birth in mrz checksum validation


mrz_expiration_date_checksum: Expiry date in mrz checksum validation


mrz_personal_number_checksum: Personnal number in mrz checksum validation


mrz_last_name_checksum: Last name in mrz checksum validation


mrz_checksum: Full mrz checksum validation

 

Here is an python code for validating machine readable zone checksums:

def check_sum(s):
    """
    https://en.wikipedia.org/wiki/Machine-readable_passport
    :param s: string
    :return: checksum value for string s
    """
    assert type(s) is str
    
    checker = 0
    alpha_to_num = {c: 10 + i for i, c in enumerate('ABCDEFGHIJKLMNOPQRSTUVWXYZ')}
    for i, c in enumerate(s):
        if i % 3 == 0:
            weight = 7
        elif i % 3 == 1:
            weight = 3
        else:
            weight = 1

        if c == '<':
            val = 0
        elif c.isalpha():
            val = alpha_to_num[c]
        else:
            val = int(c)
        checker += val * weight
    return str(checker % 10)