Python library for the Onfido API
Actively maintained. Last release 3 weeks ago, commits in 9 of the last 26 weeks. A safe choice.
pip install onfido-pythonOnfido Python Library
The official Python library for integrating with the Onfido API.
Documentation is available at https://documentation.onfido.com.
This version uses Onfido API v3.6. Refer to our API versioning guide for details. It explains which client library versions use which versions of the API.
Installation & Usage
Requirements
Python 3.9+
Installation
Pip
If the Python package is hosted on a repository, you can install it directly using:
pip install onfido-python
Then import the package:
import onfido
Poetry
poetry add onfido-python
Then import the package:
import onfido
Tests
Execute pytest to run the tests.
Getting Started
Import the DefaultApi object, this is the main object used for interfacing with the API:
import onfido
import urllib3
from os import environ
configuration = onfido.Configuration(
api_token=environ['ONFIDO_API_TOKEN'],
region=onfido.configuration.Region.EU, # Supports `EU`, `US` and `CA`
timeout=urllib3.util.Timeout(connect=60.0, read=60.0)
)
with onfido.ApiClient(configuration) as api_client:
onfido_api = onfido.DefaultApi(api_client)
...
You can also authenticate using OAuth2 client credentials instead of an API token:
configuration = onfido.Configuration(
oauth_client_id=environ['ONFIDO_OAUTH_CLIENT_ID'],
oauth_client_secret=environ['ONFIDO_OAUTH_CLIENT_SECRET'],
region=onfido.configuration.Region.EU,
timeout=urllib3.util.Timeout(connect=60.0, read=60.0)
)
with onfido.ApiClient(configuration) as api_client:
onfido_api = onfido.DefaultApi(api_client)
...
The client will automatically exchange credentials for an access token and refresh it when it expires.