or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

client-foundation.mdconfiguration-profiles.mdcredential-management.mdhttp-infrastructure.mdindex.mdresilience-reliability.mdsecurity-authentication.md
tile.json

tessl/pypi-tencentcloud-sdk-python-common

Common utilities and core components for Tencent Cloud SDK for Python, providing credential management, HTTP clients, authentication, error handling, and foundational classes required by all Tencent Cloud service SDKs

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/tencentcloud-sdk-python-common@3.0.x

To install, run

npx @tessl/cli install tessl/pypi-tencentcloud-sdk-python-common@3.0.0

index.mddocs/

Tencent Cloud SDK Python Common

Common utilities and core components for Tencent Cloud SDK for Python, providing credential management, HTTP clients, authentication, error handling, and foundational classes required by all Tencent Cloud service SDKs. This package serves as the foundational layer for the entire Tencent Cloud SDK ecosystem, enabling developers to build applications that integrate with Tencent Cloud services through a consistent, well-architected foundation.

Package Information

  • Package Name: tencentcloud-sdk-python-common
  • Type: Library
  • Language: Python
  • Installation: pip install tencentcloud-sdk-python-common

Core Imports

# Import specific credential classes
from tencentcloud.common.credential import Credential, CVMRoleCredential, STSAssumeRoleCredential

# Import client base classes
from tencentcloud.common.abstract_client import AbstractClient
from tencentcloud.common.common_client import CommonClient

# Import profile configuration
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile

# Import exception handling
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException

Basic Usage

from tencentcloud.common.credential import Credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.common_client import CommonClient

# Create credentials
cred = Credential("your-secret-id", "your-secret-key")

# Configure HTTP profile
http_profile = HttpProfile()
http_profile.endpoint = "cvm.tencentcloudapi.com"

# Configure client profile
client_profile = ClientProfile()
client_profile.httpProfile = http_profile

# Create common client
client = CommonClient("cvm", "2017-03-12", cred, "ap-guangzhou", client_profile)

# Make API call
response = client.call_json("DescribeInstances", {})
print(response)

Architecture

The package follows a layered architecture with clear separation of concerns:

  • Credential Layer: Multiple credential providers with automatic fallback chain
  • Transport Layer: HTTP connection management with pooling, proxies, and resilience features
  • Client Layer: Abstract base classes that service-specific clients inherit from
  • Configuration Layer: Flexible profile system for HTTP settings, signatures, and regional failover
  • Resilience Layer: Circuit breakers, retry mechanisms, and error handling
  • Security Layer: Multiple signature methods and authentication strategies

This design enables consistent behavior across all Tencent Cloud service SDKs while providing flexibility for different deployment scenarios and authentication methods.

Capabilities

Credential Management

Multiple credential providers supporting environment variables, configuration files, instance roles, STS temporary credentials, and OIDC tokens. Includes automatic credential chain resolution for flexible deployment scenarios.

class Credential:
    def __init__(self, secret_id: str, secret_key: str, token: str = None): ...
    def get_credential_info(self) -> tuple[str, str, str]: ...

class DefaultCredentialProvider:
    def __init__(self): ...
    def get_credentials(self): ...

Credential Management

HTTP Infrastructure

Comprehensive HTTP client implementation with connection pooling, proxy support, pre-connected pools for performance, and custom certificate handling. Supports both HTTP and HTTPS with configurable timeouts and keep-alive.

class ApiRequest:
    def __init__(self, host: str, req_timeout: int = 60, debug: bool = False, 
                 proxy: str = None, is_http: bool = False, certification = None,
                 pre_conn_pool_size: int = 0): ...
    def send_request(self, req_inter: RequestInternal): ...

HTTP Infrastructure

Client Foundation

Abstract base classes providing the foundation for all Tencent Cloud service clients. Handles request building, signature generation, response processing, and error handling with support for multiple signature methods.

class AbstractClient:
    def __init__(self, credential, region: str, profile: ClientProfile = None): ...
    def call_json(self, action: str, params: dict, headers: dict = None, 
                  options: dict = None) -> dict: ...
    def call_sse(self, action: str, params: dict, headers: dict = None,
                 options: dict = None): ...

Client Foundation

Configuration Profiles

Flexible configuration system for HTTP settings, signature methods, language preferences, and regional failover. Supports customization of endpoints, timeouts, retry policies, and circuit breaker settings.

class ClientProfile:
    def __init__(self, signMethod: str = None, httpProfile: HttpProfile = None,
                 language: str = "zh-CN", disable_region_breaker: bool = True,
                 region_breaker_profile = None, request_client: str = None,
                 retryer = None): ...

class HttpProfile:
    def __init__(self, protocol: str = None, endpoint: str = None,
                 reqMethod: str = "POST", reqTimeout: int = 60,
                 keepAlive: bool = False, proxy: str = None,
                 rootDomain: str = None, certification = None): ...

Configuration Profiles

Resilience and Reliability

Circuit breaker implementation for regional failover and retry mechanisms with configurable backoff strategies. Provides automatic failure detection and recovery for improved reliability.

class CircuitBreaker:
    def __init__(self, breaker_setting): ...
    def before_requests(self) -> tuple[int, bool]: ...
    def after_requests(self, before: int, success: bool): ...

class StandardRetryer:
    def __init__(self, max_attempts: int = 3, backoff_fn = None, logger = None): ...
    def send_request(self, fn): ...

Resilience and Reliability

Security and Authentication

Digital signature utilities supporting multiple signature methods (HmacSHA1, HmacSHA256, TC3-HMAC-SHA256) and comprehensive exception handling for authentication and API errors.

class Sign:
    @staticmethod
    def sign(secret_key: str, sign_str: str, sign_method: str) -> str: ...
    @staticmethod
    def sign_tc3(secret_key: str, date: str, service: str, str2sign: str) -> str: ...

class TencentCloudSDKException(Exception):
    def __init__(self, code: str = None, message: str = None, 
                 requestId: str = None): ...

Security and Authentication

Error Handling

All operations may raise TencentCloudSDKException with specific error codes:

  • ClientError: Configuration or parameter errors
  • ClientNetworkError: Network connectivity issues
  • ServerNetworkError: Server-side network problems
  • InvalidCredential: Authentication failures
  • RequestLimitExceeded: Rate limiting errors

Dependencies

  • requests: HTTP library (>=2.16.0)
  • certifi: Certificate management
  • urllib3: HTTP connection pooling
  • configparser: Configuration file parsing (Python 2/3 compatibility)