Volcengine SDK for Python

1.0.220 · active · verified Thu Apr 16

The `volcengine` library is the official Python SDK for interacting with Volcengine cloud services. It provides client interfaces for various services like STS, ECS, IAM, and more. It is actively maintained with frequent releases, often on a daily or weekly basis.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes the Security Token Service (STS) client and calls `GetCallerIdentity` to retrieve the current user's identity. It expects `VOLCENGINE_ACCESSKEYID`, `VOLCENGINE_SECRETACCESSKEY`, and `VOLCENGINE_REGION` to be set as environment variables.

import os
from volcengine.sts.StsService import StsService
from volcengine.sts.model.sts_pb2 import GetCallerIdentityRequest

# Initialize STS service client with credentials from environment variables
sts_service = StsService()
sts_service.set_ak(os.environ.get("VOLCENGINE_ACCESSKEYID", ""))
sts_service.set_sk(os.environ.get("VOLCENGINE_SECRETACCESSKEY", ""))
sts_service.set_region(os.environ.get("VOLCENGINE_REGION", "cn-beijing")) # Default to cn-beijing if not set

# Create a request object
req = GetCallerIdentityRequest()

try:
    # Call the API
    resp = sts_service.get_caller_identity(req)
    # Print the response
    print("Successfully called GetCallerIdentity:")
    print(f"  Account ID: {resp.AccountId}")
    print(f"  User ID: {resp.UserId}")
    print(f"  User Name: {resp.UserName}")
except Exception as e:
    print(f"Error calling GetCallerIdentity: {e}")

view raw JSON →