Aliyun Python SDK Core

2.16.0 · maintenance · verified Sat Mar 28

The `aliyun-python-sdk-core` is the foundational module of the Alibaba Cloud Python SDK (V1.0). It provides essential functionalities such as the client object, signature logic, and common exception handling, simplifying the process of integrating Python applications with various Alibaba Cloud services. While still actively maintained for security, new feature development has ceased, and Alibaba Cloud recommends migrating new projects to the V2.0 SDK for enhanced performance and features.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `AcsClient` with AccessKey credentials and a region ID. Credentials should ideally be managed via environment variables for security. After initialization, you would typically import and configure service-specific request objects and use the client to send API calls.

import os
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException, ServerException

ACCESS_KEY_ID = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', 'YOUR_ACCESS_KEY_ID')
ACCESS_KEY_SECRET = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', 'YOUR_ACCESS_KEY_SECRET')
REGION_ID = os.environ.get('ALIBABA_CLOUD_REGION_ID', 'cn-hangzhou') # e.g., 'cn-hangzhou'

try:
    # Initialize the AcsClient instance
    client = AcsClient(ACCESS_KEY_ID, ACCESS_KEY_SECRET, REGION_ID)
    print(f"AcsClient initialized successfully for region {REGION_ID}")
    # In a real scenario, you would then create a request object for a specific service
    # and send it using client.do_action_with_exception(request)
    # For example:
    # from aliyunsdkecs.request.v20140526 import DescribeRegionsRequest
    # request = DescribeRegionsRequest.DescribeRegionsRequest()
    # response = client.do_action_with_exception(request)
    # print(response.decode('utf-8'))
except ClientException as e:
    print(f"Client Error: {e.error_code} - {e.message}")
except ServerException as e:
    print(f"Server Error: {e.error_code} - {e.message}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →