alibabacloud-sdk-client-initialization-for-python

Initialize and manage Alibaba Cloud SDK clients in Python. Covers singleton pattern, thread safety, endpoint vs region configuration, VPC endpoints, async mode, and file upload APIs. Use when the user creates SDK clients, configures endpoints, asks about thread safety, singleton patterns, async calls, or VPC endpoint setup in the Python SDK.

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "alibabacloud-sdk-client-initialization-for-python" with this command: npx skills add yndu13/alibabacloud-sdk-client-initialization-for-python

Client Initialization Best Practices (Python)

Core Rules

  • Client is thread-safe — safe to share across threads without additional locking.
  • Use singleton pattern — do NOT create new client instances per request. Frequent client creation wastes resources.
  • Prefer explicit endpoint over region-based endpoint resolution.

Recommended Client Creation

import os
from threading import Lock
from alibabacloud_tea_openapi.models import Config
from alibabacloud_ecs20140526.client import Client as EcsClient

_client = None
_lock = Lock()

def get_ecs_client() -> EcsClient:
    global _client
    if _client is None:
        with _lock:
            if _client is None:
                config = Config(
                    access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
                    access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'],
                    endpoint='ecs.cn-hangzhou.aliyuncs.com',
                )
                _client = EcsClient(config)
    return _client

Endpoint Configuration

Priority: explicit endpoint > region-based resolution via region_id.

# Preferred: explicit endpoint
config = Config(endpoint='ecs.cn-hangzhou.aliyuncs.com')

# Alternative: SDK resolves endpoint from region
config = Config(region_id='cn-hangzhou')

VPC Endpoints

Use VPC endpoints when running inside Alibaba Cloud VPC:

config = Config(endpoint='ecs-vpc.cn-hangzhou.aliyuncs.com')

File Upload APIs (Advance)

Set both region_id and endpoint to the same region. Optionally set open_platform_endpoint and endpoint_type for VPC:

config = Config(
    region_id='cn-shanghai',
    endpoint='objectdet.cn-shanghai.aliyuncs.com',
    open_platform_endpoint='openplatform-vpc.cn-shanghai.aliyuncs.com',
    endpoint_type='internal',
)

SDK Components

ComponentInstall Command
Core SDKpip install alibabacloud-tea-openapi
Product SDKpip install alibabacloud_ecs20140526 (example)

Async Mode

Python SDK supports async calls via _async method suffix:

import asyncio
from alibabacloud_ecs20140526.client import Client
from alibabacloud_ecs20140526.models import DescribeImagesRequest
from alibabacloud_tea_openapi.models import Config

async def main():
    config = Config(
        access_key_id=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID'),
        access_key_secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET'),
        endpoint='ecs-cn-hangzhou.aliyuncs.com',
    )
    client = Client(config)
    request = DescribeImagesRequest(region_id='cn-hangzhou')
    response = await client.describe_images_async(request)
    return response

asyncio.run(main())

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

jirac

Jira issue management skill for OpenClaw using the jirac CLI. Requires the `jirac` binary to be installed and authenticated before use. Use when listing, vie...

Registry SourceRecently Updated
Coding

Clickup

Clickup integration. Manage project management and ticketing data, records, and workflows. Use when the user wants to interact with Clickup data.

Registry SourceRecently Updated
Coding

DingTalk Workspace CLI

管理钉钉产品能力(AI表格/日历/通讯录/群聊与机器人/待办/审批/考勤/日志/DING消息/开放平台文档/钉钉文档/钉钉云盘/AI听记/邮箱等)。当用户需要操作表格数据、管理日程会议、查询通讯录、管理群聊、机器人发消息、创建待办、提交审批、查看考勤、提交日报周报(钉钉日志模版)、读写钉钉文档、上传下载云盘文件、...

Registry SourceRecently Updated
Coding

Mistral Mcp Openclaw

Configure OpenClaw to use the community mistral-mcp stdio server for Mistral OCR, Codestral FIM, Voxtral audio, moderation, classification, files, batch, and...

Registry SourceRecently Updated