Delinea Secret Server Python SDK

2.0.1 · active · verified Thu Apr 16

The Delinea Secret Server Python SDK (version 2.0.1) provides Python classes to interact with Delinea Secret Server and Delinea Platform via their REST APIs. It supports various authentication methods and facilitates programmatic access to secrets. The library is actively maintained with regular releases and requires Python 3.8 or higher.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with Delinea Secret Server Cloud using a username and password and then retrieve a secret by its ID. It relies on environment variables for sensitive credentials.

import os
from delinea.secrets.server import (
    SecretServerCloud,
    PasswordGrantAuthorizer,
    SecretServerError
)

# Ensure these environment variables are set:
# TSS_TENANT (e.g., 'mytenant')
# TSS_USERNAME
# TSS_PASSWORD

try:
    tenant = os.environ.get('TSS_TENANT', '')
    username = os.environ.get('TSS_USERNAME', '')
    password = os.environ.get('TSS_PASSWORD', '')

    if not all([tenant, username, password]):
        raise ValueError("TSS_TENANT, TSS_USERNAME, and TSS_PASSWORD environment variables must be set.")

    # For Secret Server Cloud, 'tenant' parameter simplifies URL construction
    authorizer = PasswordGrantAuthorizer(
        base_url=f"https://{tenant}.secretservercloud.com",
        username=username,
        password=password
    )

    secret_server_cloud = SecretServerCloud(tenant=tenant, authorizer=authorizer)

    # Example: Fetch a secret by ID
    secret_id = 123 # Replace with a valid secret ID from your Secret Server
    secret = secret_server_cloud.get_secret(secret_id)
    print(f"Successfully fetched secret with ID {secret_id}:")
    print(f"Secret Name: {secret.name}")
    # Access secret fields, e.g., secret.data['username'] or secret.data['password']

except SecretServerError as e:
    print(f"Secret Server Error: {e.message}")
    print("Please check your credentials, tenant URL, and permissions.")
except ValueError as e:
    print(f"Configuration Error: {e}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →