Duo Security Python Client

5.6.1 · active · verified Mon Apr 13

The `duo-client` library provides a reference Python client for interacting with Duo Security's Auth, Admin, and Accounts APIs. It is actively maintained with frequent releases, offering programmatic access to manage users, policies, and authentication events. The current version is 5.6.1, and it supports Python 3.7 and higher.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the AuthApi client and perform a basic service check. It emphasizes the importance of loading sensitive API credentials from environment variables for security. Ensure DUO_IKEY, DUO_SKEY, and DUO_HOST are set in your environment or replaced with actual values.

import os
from duo_client.auth import AuthApi

# It's crucial to load credentials from environment variables or a secure secret store.
# DO NOT hardcode IKEY, SKEY, or HOST in your application code.
IKEY = os.environ.get('DUO_IKEY', 'DIXXXXXXXXXXXXXXXXXX') # Replace with your actual Integration Key
SKEY = os.environ.get('DUO_SKEY', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') # Replace with your actual Secret Key
HOST = os.environ.get('DUO_HOST', 'api-xxxxxxxx.duosecurity.com') # Replace with your actual API Hostname

if IKEY == 'DIXXXXXXXXXXXXXXXXXX' or SKEY == 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' or HOST == 'api-xxxxxxxx.duosecurity.com':
    print("Warning: Please set DUO_IKEY, DUO_SKEY, and DUO_HOST environment variables or replace placeholder values.")
    print("Skipping quickstart execution due to placeholder credentials.")
else:
    try:
        # Initialize the Auth API client
        auth_api = AuthApi(
            ikey=IKEY,
            skey=SKEY,
            host=HOST,
        )

        # Make a simple API call to check service status
        response = auth_api.check()
        print("Duo Auth API Check successful:")
        print(response)
    except Exception as e:
        print(f"Error checking Duo Auth API: {e}")

view raw JSON →