Overview

This guide will help you extract data from W9s using Butler's OCR APIs in Python. In 15 minutes you'll be ready to add Python W9 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 W9 model:

2880

Click on the W9 card, then press the Try Now button to create a new W9 model:

2880

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

2880

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

Sample Python W9 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_w9.pdf')
# 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 W9 Fields

Here is an example of what an W9 JSON response looks like:

{
  "documentId": "59b1ea9b-cd96-482e-8fc7-36d18c778aa6",
  "documentStatus": "Completed",
  "fileName": "w9-sample-2.png",
  "mimeType": "image/png",
  "documentType": "W9s",
  "confidenceScore": "High",
  "formFields": [
    {
      "fieldName": "Form Revision Date",
      "value": "( Rev. October 2018)",
      "confidenceScore": "High"
    },
    {
      "fieldName": "Name",
      "value": "Paul Sakhatskyi",
      "confidenceScore": "High"
    },
    {
      "fieldName": "Business Name",
      "value": "Readdle Inc",
      "confidenceScore": "High"
    },
    {
      "fieldName": "Federal Tax Classification",
      "value": "CCorporation",
      "confidenceScore": "High"
    },
    {
      "fieldName": "Federal Tax Classification Other",
      "value": "(",
      "confidenceScore": "Low"
    },
    {
      "fieldName": "Address",
      "value": "795 Folsom St",
      "confidenceScore": "Low"
    },
    {
      "fieldName": "City State Zip",
      "value": "San Francisco, CA 94107",
      "confidenceScore": "High"
    },
    {
      "fieldName": "Has Signature",
      "value": "NO",
      "confidenceScore": "Low"
    },
    {
      "fieldName": "Has Signature Date",
      "value": "NO",
      "confidenceScore": "Low"
    }
  ],
  "tables": []
}

📘

W9 API Response Details

For full details about the W9 Model and its API response, see the W9 page.