Onfido Python SDK

6.0.0 · active · verified Sat Apr 11

The official Python library for integrating with the Onfido API. This version (6.0.0) is built using OpenAPI Generator and currently uses Onfido API v3.6. It is actively maintained and frequently updated in line with the Onfido OpenAPI specification, with major versions often introducing non-backward compatible changes.

Warnings

Install

Imports

Quickstart

Initializes the Onfido API client with an API token and region, then demonstrates how to create and retrieve an applicant. The API token should be provided via an environment variable for security. Default timeouts are 30 seconds but can be customized.

import onfido
import urllib3
import os

# Ensure ONFIDO_API_TOKEN is set in your environment
ONFIDO_API_TOKEN = os.environ.get('ONFIDO_API_TOKEN', 'YOUR_API_TOKEN_HERE')

# Configure the Onfido API client
configuration = onfido.Configuration(
    api_token=ONFIDO_API_TOKEN,
    region=onfido.configuration.Region.EU, # Or US, CA, or custom base_url
    timeout=urllib3.util.Timeout(connect=60.0, read=60.0)
)

with onfido.ApiClient(configuration) as api_client:
    onfido_api = onfido.DefaultApi(api_client)

    try:
        # Create an applicant
        applicant = onfido_api.create_applicant(
            onfido.ApplicantBuilder(
                first_name='John',
                last_name='Doe'
            )
        )
        print(f"Created Applicant ID: {applicant.id}")

        # Example: Retrieve the applicant
        retrieved_applicant = onfido_api.find_applicant(applicant.id)
        print(f"Retrieved Applicant Name: {retrieved_applicant.first_name} {retrieved_applicant.last_name}")

    except onfido.ApiException as e:
        print(f"Onfido API Error: {e.body}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

view raw JSON →