Comprehensive Python SDK for integrating with Tencent Cloud services, supporting 240+ cloud services with authentication, error handling, and retry mechanisms.
npx @tessl/cli install tessl/pypi-tencentcloud-sdk-python@3.0.0A comprehensive Software Development Kit (SDK) for integrating with Tencent Cloud services, enabling Python developers to programmatically access and manage over 240 cloud services including CVM (Cloud Virtual Machine), CBS (Cloud Block Storage), and numerous other Tencent Cloud products. The SDK offers a unified API interface with automatic request signing, authentication handling, and error management.
pip install tencentcloud-sdk-pythonrequests>=2.16.0# Core authentication and client infrastructure
from tencentcloud.common import credential
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
# Service-specific imports (example with CVM)
from tencentcloud.cvm.v20170312 import cvm_client, models
# Generic client for any service
from tencentcloud.common.common_client import CommonClientimport os
from tencentcloud.common import credential
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.cvm.v20170312 import cvm_client, models
try:
# Initialize credentials (recommended: use environment variables)
cred = credential.Credential(
os.environ.get("TENCENTCLOUD_SECRET_ID"),
os.environ.get("TENCENTCLOUD_SECRET_KEY")
)
# Create service client
client = cvm_client.CvmClient(cred, "ap-shanghai")
# Create request object
req = models.DescribeInstancesRequest()
# Call API
resp = client.DescribeInstances(req)
# Handle response
print(resp.to_json_string())
except TencentCloudSDKException as err:
print(f"Error: {err.get_code()} - {err.get_message()}")The TencentCloud SDK follows a consistent, hierarchical structure across all 242 cloud services:
AbstractClient, AbstractModel) providing common functionalityEach service follows the pattern: tencentcloud.{service}.{version}.{service}_client and tencentcloud.{service}.{version}.models.
Multiple authentication methods supporting various deployment scenarios including development, production, container environments, and cross-account access.
class Credential:
def __init__(self, secret_id: str, secret_key: str, token: str = None): ...
class CVMRoleCredential:
def __init__(self, role_name: str = None): ...
class STSAssumeRoleCredential:
def __init__(self, secret_id: str, secret_key: str, role_arn: str, role_session_name: str, duration_seconds: int = 7200): ...
class EnvironmentVariableCredential:
def __init__(self): ...
class ProfileCredential:
def __init__(self, profile_name: str = None, profile_path: str = None): ...
class DefaultCredentialProvider:
def __init__(self): ...Authentication and Credentials
Core client classes providing HTTP communication, request signing, error handling, and logging capabilities for all Tencent Cloud services.
class AbstractClient:
def __init__(self, credential, region: str, profile = None): ...
def set_stream_logger(self, stream, level): ...
def set_file_logger(self, file_path: str, level): ...
class CommonClient(AbstractClient):
def __init__(self, service: str, version: str, credential, region: str, profile = None): ...
def call_json(self, action: str, params: dict, headers: dict = None): ...Comprehensive configuration system for HTTP settings, retry behavior, circuit breakers, and request customization.
class ClientProfile:
def __init__(self, signMethod: str = "TC3-HMAC-SHA256", httpProfile = None, language: str = "zh-CN", debug: bool = False): ...
class HttpProfile:
def __init__(self, protocol: str = "https", endpoint: str = None, reqMethod: str = "POST", reqTimeout: int = 60): ...
class RegionBreakerProfile:
def __init__(self, backup_endpoint: str, max_fail_num: int = 5, max_fail_percent: float = 0.75): ...Unified exception handling and configurable retry mechanisms with exponential backoff for robust cloud service integration.
class TencentCloudSDKException(Exception):
def __init__(self, code: str = None, message: str = None, requestId: str = None): ...
def get_code(self) -> str: ...
def get_message(self) -> str: ...
def get_request_id(self) -> str: ...
class StandardRetryer:
def __init__(self, max_attempts: int = 3, backoff_fn = None, logger = None): ...
class NoopRetryer:
def __init__(self): ...Service-specific client classes for accessing Tencent Cloud APIs. All service clients follow a consistent pattern and inherit from AbstractClient.
Core Compute Services:
Storage Services:
Networking Services:
# Example service client signatures (CVM, CBS, VPC)
class CvmClient(AbstractClient):
def __init__(self, credential, region: str, profile = None): ...
def DescribeInstances(self, request) -> models.DescribeInstancesResponse: ...
def RunInstances(self, request) -> models.RunInstancesResponse: ...
def TerminateInstances(self, request) -> models.TerminateInstancesResponse: ...
class CbsClient(AbstractClient):
def __init__(self, credential, region: str, profile = None): ...
def CreateDisks(self, request) -> models.CreateDisksResponse: ...
def AttachDisks(self, request) -> models.AttachDisksResponse: ...
def DetachDisks(self, request) -> models.DetachDisksResponse: ...
class VpcClient(AbstractClient):
def __init__(self, credential, region: str, profile = None): ...
def CreateVpc(self, request) -> models.CreateVpcResponse: ...
def CreateSubnet(self, request) -> models.CreateSubnetResponse: ...
def DescribeVpcs(self, request) -> models.DescribeVpcsResponse: ...Base model class and service-specific request/response models providing JSON serialization and data validation for all API interactions.
class AbstractModel:
def __init__(self): ...
def to_json_string(self, indent: int = None) -> str: ...
def from_json_string(self, json_string: str): ...
# Example model classes (all models inherit from AbstractModel)
class DescribeInstancesRequest(AbstractModel):
def __init__(self): ...
class DescribeInstancesResponse(AbstractModel):
def __init__(self): ...
class Instance(AbstractModel):
def __init__(self): ...# Core credential interface
class CredentialInterface:
def get_credential(self): ...
# Request/response base
class AbstractModel:
def to_json_string(self, indent: int = None) -> str: ...
def from_json_string(self, json_string: str): ...
def _serialize(self) -> dict: ...
# Filter for query operations
class Filter:
def __init__(self):
self.Name: str = None
self.Values: list = None
# Basic pagination
class Paging:
def __init__(self):
self.Offset: int = None
self.Limit: int = None
# Common placement information
class Placement:
def __init__(self):
self.Zone: str = None
self.ProjectId: int = None
self.HostIds: list = None