Akeyless Python SDK

5.0.23 · active · verified Wed Apr 15

The Akeyless Python SDK facilitates integration of Python applications, libraries, or scripts with the Akeyless Vaultless Platform for secrets management, encryption, and access control. It allows secure interaction with Akeyless services to retrieve and manage various types of secrets. The current version is 5.0.23, and the library is actively maintained with frequent updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with Akeyless using an API Key and retrieve a static secret. It's crucial to manage your Access ID and Access Key securely, preferably via environment variables, and avoid hardcoding them. The `AKEYLESS_API_HOST` environment variable can be used to specify a different Akeyless Gateway endpoint if needed. After authentication, the obtained token must be included in subsequent API calls.

import akeyless
import os

# Configure API key authentication
# It's recommended to use environment variables or a secure configuration management system
access_id = os.environ.get('AKEYLESS_ACCESS_ID', 'your_access_id')
access_key = os.environ.get('AKEYLESS_ACCESS_KEY', 'your_access_key')

# Optional: Configure the Akeyless host (defaults to https://api.akeyless.io)
configuration = akeyless.Configuration(
    host=os.environ.get('AKEYLESS_API_HOST', 'https://api.akeyless.io')
)

with akeyless.ApiClient(configuration) as api_client:
    # Create an instance of the API class
    api_instance = akeyless.V2Api(api_client)

    try:
        # Authenticate to get a session token
        auth_body = akeyless.Auth(
            access_id=access_id,
            access_key=access_key
        )
        auth_response = api_instance.auth(auth_body)
        token = auth_response.token
        print(f"Authentication successful. Token obtained.")

        # Retrieve a static secret value
        secret_name = "/my-app/database-password"
        get_secret_body = akeyless.GetSecretValue(
            names=[secret_name],
            token=token
        )
        secret_response = api_instance.get_secret_value(get_secret_body)
        secret_value = secret_response.get(secret_name, "Secret not found")
        print(f"Retrieved secret '{secret_name}': {secret_value}")

    except ApiException as e:
        print(f"Exception when calling Akeyless API: {e}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

view raw JSON →