Okta Python SDK
The `okta` Python SDK provides a client for interacting with the Okta Management API, enabling developers to manage users, applications, groups, and other Okta resources. It's currently on version 3.4.0 and receives frequent updates, with minor versions released often and major versions (e.g., v3.0.0) introducing significant API changes every few months.
Warnings
- breaking Version 3.0.0 introduced significant breaking changes by upgrading the SDK to OpenAPI Specification (OAS3.0). This may affect method signatures, request/response object structures, and API endpoint availability compared to 2.x.x versions.
- breaking Versions 3.0.0 and 3.1.0 contain a critical bug that causes malformed requests for OAuth access tokens, preventing successful authentication via OAuth 2.0 client credentials or other OAuth flows.
- gotcha Prior to version 2.9.9, the `client_assertion` JWT for client credentials flow was incorrectly placed in the URL query parameters instead of the request body, potentially causing authentication failures or security concerns.
- gotcha In versions prior to 2.9.13, the SDK might not properly handle the expiration and renewal of OAuth 2.0 access tokens, potentially leading to errors when tokens expire during long-running operations.
- gotcha Prior to version 3.3.0, the SDK might fail to deserialize or gracefully handle Application objects with unknown `signOnMode` values, leading to errors when retrieving application data if new modes are introduced by Okta.
Install
-
pip install okta
Imports
- Client
from okta.client import Client
Quickstart
import os
from okta.client import Client as OktaClient
# Configure the Okta client using environment variables
# OKTA_ORG_URL should be your Okta tenant URL, e.g., https://your-org.okta.com
# OKTA_TOKEN should be an API Token with sufficient permissions (e.g., Read only administrator)
config = {
'orgUrl': os.environ.get('OKTA_ORG_URL', ''),
'token': os.environ.get('OKTA_TOKEN', ''),
'rateLimit': {
'maxRetries': 5
}
}
# Initialize the Okta client
okta_client = OktaClient(config)
# Example: List users
try:
# list_users() returns (users_list, response_object, error)
users, response, err = okta_client.list_users()
if err:
print(f"Error listing users: {err}")
elif users:
print(f"Successfully retrieved {len(users)} users. Showing first 3:")
for i, user in enumerate(users[:3]):
print(f"- User ID: {user.id}, Login: {user.profile.login}")
else:
print("No users found or empty response.")
except Exception as e:
print(f"An unexpected error occurred: {e}")
# To run this example, set the following environment variables:
# export OKTA_ORG_URL="https://your-okta-domain.okta.com"
# export OKTA_TOKEN="your_okta_api_token"