Welcome to the Alibaba Cloud Software Development Kit (SDK). The Alibaba Cloud Python Software Development Kit (SDK) allows you to access Alibaba Cloud services such as Elastic Compute Service (ECS), Server Load Balancer (SLB), and CloudMonitor. This document introduces how to obtain and call Alibaba Cloud Python SDK. If you have any problem while using the SDK, please join the DingTalk group: 11771185 (the official SDK customer service group of Alibaba Cloud) for consultation.
Prepare the environment
- To use Alibaba Cloud Python SDK, you must have an Alibaba Cloud account as well as an AccessKey. To use Alibaba Cloud Python SDK, you must have an Alibaba Cloud account as well as an AccessKey ID and an AccessKey Secret. Create and view your AccessKey on the RAM console or contact your system administrator.
- To use Alibaba Cloud Python SDK to access the APIs of a product, you must first activate the product on the Alibaba Cloud console if required.
Install Python SDK
- Install SDK core library.
- If you use Python 2.x, run the following command to install Alibaba Cloud SDK core
pip install aliyun-python-sdk-core
- If you use Python 3.x, run the following command to install Alibaba Cloud SDK core
pip install aliyun-python-sdk-core-v3
- If you use Python 2.x, run the following command to install Alibaba Cloud SDK core library:
- Install the SDK for the cloud product.
The following is an SDK example for installing ECS:
pip install aliyun-python-sdk-ecs
You can download product SDKs from GitHub.
Use Python SDK
The following code example shows the three main steps for calling the Alibaba Cloud Python SDK:
- Creates a client instance. When creating the client instance, you must obtain the Region ID, the AccessKey ID, and the AccessKey Secret.
- Create an API request and set parameters.
- Initiate a request and handle the response or exceptions.
# -*- coding: utf8 -*- from aliyunsdkcore.client import AcsClient from aliyunsdkcore.acs_exception.exceptions import ClientException from aliyunsdkcore.acs_exception.exceptions import ServerException from aliyunsdkecs.request.v20140526 import DescribeInstancesRequest from aliyunsdkecs.request.v20140526 import StopInstanceRequest # Create an AcsClient instance client = AcsClient( "<your-access-key-id>", "<your-access-key-secret>", "<your-region-id>" # Create a request and set parameters request = DescribeInstancesRequest.DescribeInstancesRequest() request.set_PageSize(10) # Initiate an API request and display the response value response = client.do_action_with_exception(request) print response