The core module of Aliyun Python SDK providing authentication, request handling, and API communication for Alibaba Cloud services.
npx @tessl/cli install tessl/pypi-aliyun-python-sdk-core@2.16.0The core module of Aliyun Python SDK providing authentication, request handling, and API communication for Alibaba Cloud services. This package serves as the foundation for all other Alibaba Cloud Python SDK service modules, offering standardized client initialization, credential management, request/response processing, and error handling.
pip install aliyun-python-sdk-corefrom aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import RpcRequest, RoaRequest, CommonRequest
from aliyunsdkcore.auth.credentials import AccessKeyCredential, StsTokenCredential, RamRoleArnCredential, EcsRamRoleCredential, RsaKeyPairCredential
from aliyunsdkcore.acs_exception.exceptions import ClientException, ServerExceptionfrom aliyunsdkcore.client import AcsClient
from aliyunsdkcore.auth.credentials import AccessKeyCredential
from aliyunsdkcore.request import CommonRequest
# Initialize client with credentials
credential = AccessKeyCredential("your-access-key-id", "your-access-key-secret")
client = AcsClient(credential=credential, region_id="cn-hangzhou")
# Create a request
request = CommonRequest()
request.set_method("POST")
request.set_domain("ecs.cn-hangzhou.aliyuncs.com")
request.set_version("2014-05-26")
request.set_action_name("DescribeInstances")
# Execute request
response = client.do_action_with_exception(request)
print(response.decode('utf-8'))The SDK follows a layered architecture:
AcsClient manages API communication, authentication, and retry logicAcsRequest and subclasses (RpcRequest, RoaRequest, CommonRequest) define API request structureCore client functionality for API communication with Alibaba Cloud services, including authentication, request execution, retry logic, and response handling.
class AcsClient:
def __init__(
self,
ak=None,
secret=None,
region_id="cn-hangzhou",
credential=None,
**kwargs
): ...
def do_action(self, acs_request): ...
def do_action_with_exception(self, acs_request): ...Different request types for various Alibaba Cloud API styles, including RPC-style requests, RESTful ROA requests, and flexible common requests.
class AcsRequest:
def __init__(self, product, version=None, action_name=None, **kwargs): ...
def set_query_params(self, params): ...
def set_content(self, content): ...
class RpcRequest(AcsRequest): ...
class RoaRequest(AcsRequest): ...
class CommonRequest(AcsRequest): ...Multiple authentication methods supporting various credential types including access keys, STS tokens, RAM roles, and RSA key pairs.
class AccessKeyCredential:
def __init__(self, access_key_id, access_key_secret): ...
class StsTokenCredential:
def __init__(self, sts_access_key_id, sts_access_key_secret, sts_token): ...
class RamRoleArnCredential:
def __init__(self, sts_access_key_id, sts_access_key_secret, role_arn, session_role_name): ...Comprehensive exception classes for handling both client-side and server-side errors with detailed error information and debugging capabilities.
class ClientException(Exception):
def __init__(self, code, msg): ...
class ServerException(Exception):
def __init__(self, code, msg, http_status, request_id): ...Flexible retry mechanisms with configurable retry conditions and backoff strategies for handling transient failures and rate limiting.
class RetryPolicy(RetryCondition, BackoffStrategy): ...
class MaxRetryTimesCondition(RetryCondition): ...
class ExponentialBackoffStrategy(BackoffStrategy): ...from typing import Dict, Any, Optional, Union
# HTTP method types
class MethodType:
GET: str
POST: str
PUT: str
DELETE: str
HEAD: str
OPTIONS: str
# Protocol types
class ProtocolType:
HTTP: str
HTTPS: str
# Format types
class FormatType:
JSON: str
XML: str
RAW: str
APPLICATION_FORM: str
APPLICATION_XML: str
APPLICATION_JSON: str
APPLICATION_OCTET_STREAM: str
TEXT_XML: str
# Request styles
STYLE_RPC: str
STYLE_ROA: str