Okta Python SDK

3.4.0 · active · verified Sun Apr 12

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

Install

Imports

Quickstart

Initialize the Okta client using environment variables for sensitive configuration and perform a basic API call to list users. This example demonstrates configuring the client with an API token for basic authentication. For OAuth 2.0 or private key authentication, the configuration dictionary would differ.

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"

view raw JSON →