V1.0 SDK Status:
- Currently in basic security maintenance phase
- No new features will be added
Migration Recommendations:
- New projects should directly use the V2.0 SDK
- Existing V1.0 projects are advised to migrate to V2.0 as soon as possible
- V2.0 provides better performance, a more concise API, and more complete documentation
GitHub Repository: https://github.com/aliyun/alibabacloud-python-sdk
Official Documentation: https://help.aliyun.com/zh/sdk/developer-reference/v2-python-integrated-sdk
Developer Portal: https://api.aliyun.com
If you still need to use the V1.0 SDK, please continue reading the following content:
Troubleshoot provides OpenAPI usage diagnostics. By entering the RequestID or error message, it helps developers quickly locate issues and provides corresponding solutions.
The Developer Portal provides capabilities such as invoking cloud product OpenAPIs online, dynamically generating SDK example code, and quickly searching for APIs. This can significantly reduce the difficulty of using cloud APIs and is highly recommended.
- Starting from version 2.16.0, the core library of Alibaba Cloud Python SDK,
aliyun-python-sdk-core, only supports Python 3.7 and above. - The V1.0 SDK will no longer receive new feature updates.
- It is recommended to migrate to the V2.0 SDK as soon as possible to gain better support and features.
- Environment Requirements
- Installation
- Client and Credentials
- Timeout Mechanism
- Proxy Configuration
- Logging
- Endpoints
- HTTPS Configuration
- Debugging
- Exceptions
- To use the Alibaba Cloud Python SDK, you need a cloud account and a pair of
Access Key IDandAccess Key Secret. Please create and view your Access Keys on the AccessKey management page in the Alibaba Cloud console, or contact your system administrator. - To use the Alibaba Cloud SDK to access the API of a specific product, you must first activate that product in the Alibaba Cloud Console.
pip install aliyun-python-sdk-core # Install the Alibaba Cloud SDK core library
pip install aliyun-python-sdk-ecs # Install the ECS management SDKThe following code example demonstrates the three main steps for calling the Alibaba Cloud Python SDK:
- Create a Client instance
- Create an API request and set parameters
- Send the request and handle 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)
# Send the API request and print the response
response = client.do_action_with_exception(request)
print responseWhen creating the Client instance, you need to provide three parameters: Region ID, Access Key ID, and Access Key Secret. Access Key ID and Access Key Secret can be obtained from the console, and Region ID can be found in the Region List.
To use the HTTP DEBUG feature, you need to set the DEBUG environment variable in your environment. Its value can be either sdk or SDK.
HTTP DEBUG displays the following information to help you debug your code:
> GET /databases?RegionId=cn-hangzhou HTTP/1.1
> Host : ads.cn-hangzhou.aliyuncs.com
> User-Agent : AlibabaCloud (Windows 10;AMD64) Python/3.7.1 Core/2.13.1 python-requests/2.18.1
> accept-encoding : *
> Accept : application/json
> Connection : keep-alive
> x-sdk-invoke-type : normal
> x-acs-version : 2019-01-22
> x-acs-region-id : cn-hangzhou
> Date : Thu, 21 Feb 2019 08:00:50 GMT
> x-acs-signature-method : HMAC-SHA1
> x-acs-signature-version : 1.0
> Authorization : acs ...
> x-sdk-client : python/2.0.0
< HTTP/1.1 503 SERVICE_UNAVAILABLE
< Date : Thu, 21 Feb 2019 08:00:50 GMT
< Content-Type : application/json; charset=UTF-8
< Content-Length : 297
< Connection : keep-alive
< Access-Control-Allow-Origin : *
< Access-Control-Allow-Methods : POST, GET, OPTIONS
< Access-Control-Allow-Headers : X-Requested-With, X-Sequence, _aop_secret, _aop_signature
< Access-Control-Max-Age : 172800
< x-acs-request-id : 670F3D09-F8E7-4144-83C3-B56C35DA35ED
< Server : Jetty(7.2.2.v20101205)
Please make sure to read the Contributing Guide before submitting a pull request.
We recommend using the V2.0 SDK for a better development experience! 🚀