Aliyun Python SDK Core
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
- breaking The `aliyun-python-sdk-core` (V1.0 SDK) is entering a basic security maintenance phase and will not receive new features. Alibaba Cloud strongly recommends migrating new projects to the V2.0 SDK (`alibabacloud-python-sdk`) for better performance, a more concise API, and continued feature development.
- breaking Starting from version 2.16.0, `aliyun-python-sdk-core` officially requires Python 3.7 or higher. Earlier versions supported Python 2.7 and various Python 3.x versions.
- gotcha Incorrect `region_id` format during `AcsClient` initialization can lead to `SDK.MissingEndpointsFiler` or other endpoint resolution errors. Region IDs must follow the `cn-<Region>` or equivalent cloud-specific format.
- gotcha ModuleNotFoundError for SDK components or persistent installation issues can be caused by outdated `pip` or `setuptools`, or Python version conflicts.
Install
-
pip install aliyun-python-sdk-core
Imports
- AcsClient
from aliyunsdkcore.client import AcsClient
- ClientException
from aliyunsdkcore.acs_exception.exceptions import ClientException
- ServerException
from aliyunsdkcore.acs_exception.exceptions import ServerException
Quickstart
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}")