Overview

This guide will help you extract data from Passports using Butler's OCR APIs in Python. In 15 minutes you'll be ready to add Python Passport OCR into your product or workflow!

Before getting started, you'll want to make sure to do the following:

  1. Signup for a free Butler account at https://app.butlerlabs.ai
  2. Write down your Butler API key from the Settings menu. Follow the Getting Started guide for more details about how to do that.

Get your API ID

Sign into the Butler product, go to the Library and search for the Passport model:

2880

Click on the Passports card, then press the Create button to create a new Passport model:

2880

Once on the model details page, go to the APIs tab:

1146

Copy the API ID (also known as the Queue ID) and write it down. We'll use it in our code below.

Sample Python Passport OCR Code

You can copy and paste the following Python sample code to process documents with OCR using the API.

# Ensure it's installed in your environment with pip install butler-sdk
from butler import Client

# Get API Key from https://docs.butlerlabs.ai/reference/uploading-documents-to-the-rest-api#get-your-api-key
api_key = '<api-key>'
# Get Queue ID from https://docs.butlerlabs.ai/reference/uploading-documents-to-the-rest-api#go-to-the-model-details-page
queue_id = '<queue_id>'

# Response is a strongly typed object
response = Client(api_key).extract_document(queue_id, 'sample_passport.jpeg')
# Convert to a dictionary for printing
print(response.to_dict())

📘

In-Product Sample Code

You can also copy the sample code directly from the product. This code will have your API ID and API Key already pre-populated for you!

Extracted Passport Fields

Here is an example of what a Passport JSON response looks like:

{
  "documentId": "330bf673-9fd9-4f35-9e30-2df8801ba7ce",
  "documentStatus": "Completed",
  "fileName": "sample_passport.jpeg",
  "mimeType": "image/jpeg",
  "documentType": "Passport",
  "confidenceScore": "High",
  "formFields": [
    {
      "fieldName": "Document Number",
      "value": "T123456M",
      "confidenceScore": "High"
    },
    {
      "fieldName": "First Name",
      "value": "MARYJO",
      "confidenceScore": "High"
    },
    {
      "fieldName": "Last Name",
      "value": "RAVELER",
      "confidenceScore": "High"
    },
    {
      "fieldName": "Birth Date",
      "value": "600101",
      "confidenceScore": "High"
    },
    {
      "fieldName": "Expiration Date",
      "value": "141231",
      "confidenceScore": "High"
    },
    {
      "fieldName": "Sex",
      "value": "F",
      "confidenceScore": "High"
    },
    {
      "fieldName": "Nationality",
      "value": "USA",
      "confidenceScore": "High"
    },
    {
      "fieldName": "Machine Readable Zone",
      "value": "PUSATRAVELER<<MARYJO<<<<<<<<<<<<<<<<<<<<<< T123456M<4USA6001010F1412314<<<<<<<<<<<<<<<2",
      "confidenceScore": "Low"
    }
  ],
  "tables": []
}

📘

Passport API Response Details

For more details on each of the fields returned from the Passport OCR API, see the Passport page.