or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

authentication.mdclient-management.mdexception-handling.mdindex.mdrequest-types.mdretry-backoff.md
tile.json

tessl/pypi-aliyun-python-sdk-core

The core module of Aliyun Python SDK providing authentication, request handling, and API communication for Alibaba Cloud services.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/aliyun-python-sdk-core@2.16.x

To install, run

npx @tessl/cli install tessl/pypi-aliyun-python-sdk-core@2.16.0

index.mddocs/

Aliyun Python SDK Core

The 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.

Package Information

  • Package Name: aliyun-python-sdk-core
  • Language: Python
  • Installation: pip install aliyun-python-sdk-core
  • Python Requirements: >= 3.7

Core Imports

from 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, ServerException

Basic Usage

from 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'))

Architecture

The SDK follows a layered architecture:

  • Client Layer: AcsClient manages API communication, authentication, and retry logic
  • Request Layer: AcsRequest and subclasses (RpcRequest, RoaRequest, CommonRequest) define API request structure
  • Authentication Layer: Multiple credential types and signature methods for secure API access
  • Transport Layer: HTTP request/response handling with connection pooling and timeout management
  • Exception Layer: Structured error handling for client and server-side issues
  • Utility Layer: Parameter validation, encoding, and helper functions

Capabilities

Client Management

Core 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): ...

Client Management

Request Types

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): ...

Request Types

Authentication & Credentials

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): ...

Authentication & Credentials

Exception Handling

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): ...

Exception Handling

Retry & Backoff

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): ...

Retry & Backoff

Types

Core Types

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