Volcengine SDK for Python

5.0.23 · active · verified Sun Apr 12

The Volcengine SDK for Python provides comprehensive access to Volcengine cloud services, including compute, storage, networking, and AI. It is currently at version 5.0.23 and receives frequent minor updates adding new services and API versions.

Warnings

Install

Imports

Quickstart

This quickstart initializes an IAMService client using environment variables for credentials and then attempts to list the access keys associated with the account. This demonstrates basic client setup and a simple API call.

import os
from volcengine.iam.IAMService import IAMService

# Set your Volcengine Access Key (AK) and Secret Key (SK) as environment variables
# or replace with actual credentials. NEVER hardcode production credentials.
VOLCENGINE_AK = os.environ.get("VOLCENGINE_AK", "YOUR_AK")
VOLCENGINE_SK = os.environ.get("VOLCENGINE_SK", "YOUR_SK")

if VOLCENGINE_AK == "YOUR_AK" or VOLCENGINE_SK == "YOUR_SK":
    print("Please set VOLCENGINE_AK and VOLCENGINE_SK environment variables or replace placeholders.")
    exit(1)

try:
    # Initialize the IAM service client
    iam_service = IAMService()
    iam_service.set_ak(VOLCENGINE_AK)
    iam_service.set_sk(VOLCENGINE_SK)
    # Default region is cn-beijing. You can set it explicitly if needed:
    # iam_service.set_region("cn-beijing")

    # Example: List up to 10 access keys for the current account
    print("Attempting to list access keys...")
    resp = iam_service.list_access_keys({"Limit": 10})

    if resp.get("ResponseMetadata", {}).get("Error"):
        error_message = resp["ResponseMetadata"]["Error"]["Message"]
        print(f"Error listing access keys: {error_message}")
    else:
        access_keys = resp.get("Result", {}).get("AccessKeys", [])
        print(f"Successfully listed {len(access_keys)} access keys.")
        for key in access_keys:
            print(f"  Access Key Id: {key.get('AccessKeyId')}, Status: {key.get('Status')}")

except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →