Getting started

 

 

Get started with passport parsing in python.

 

1. Install the mindee python helper library

 

Install from PyPi using pip, a package manager for Python.

 

pip install mindee

 

Don't have pip installed? Try installing it, by running this from the command line:

 

$ curl https://bootstrap.pypa.io/get-pip.py | python

 

Getting started with the Mindee API couldn't be easier. Create a Client and you're ready to go.

 

 

 

2. Instantiate your Client

 

The mindee.Client needs your API credentials. You can either pass these directly to the constructor (see the code below) or via environment variables.

 

Depending on what type of document you want to parse, you need to add specifics auth token for each endpoint.

 

from mindee import Client

mindee_client = Client(
    passport_token="your_passport_api_token_here",
    raise_on_error=True
)

 

  • passport_token: (string) API key for passports endpoint
  • raise_on_error: (boolean, default True) Specify wheter or not raising an Exception when HTTP errors occur

 

 

We suggest storing your credentials as environment variables. Why? You'll never have to worry about committing your credentials and accidentally posting them somewhere public.

 

 

 

3. Parse a Passport

 

Using the parse_passport method from your client object, you can pass any image or pdf file (see inputs file for pdf pages number limits) to get the passport data.

 

from mindee import Client

mindee_client = Client(
    passport_token="your_passport_api_token_here",
    raise_on_error=True
)

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

 

 

Input types

 

You can pass your input file in three ways:

 

From file path

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

 

 From a file object

with open('/path/to/file', 'rb') as fp:
     passport_data = mindee_client.parse_passport(fp, input_type="file")

 

From a base64

passport_data = mindee_client.parse_passport(base64_string, input_type="base64")

 

 

passport_data structure

 

The passport_data object returned by the parse_passport method contains the following elements:

 

passport_data.passport

 

The passport attribute is the Passport object constructed by gathering all the pages into a single document.

 

passport_data.passport # returns a unique object from class Passport

 

 

passport_data.passports

 

For multi pages pdf, the 'pages' attribute is a list of Passport objects, each object is constructed using a unique page of the pdf

 

passport_data.passports # [Passport, Passport ...] 

 

 

passport_data.http_response

 

Contains the full Mindee API HTTP response object

 

passport_data.http_response # full HTTP request object 

 

 

 

4. Display the results

 

You only have to print your passport object to display the different extracted fields:

 

from mindee import Client

mindee_client = Client(
    passport_token="your_passport_token_here",
    raise_on_error=True
)

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

print(passport_data.passport)