This topic describes how to install SDK for Python and provides an example of how to use SDK for Python.

Install SDK for Python

Run the pip command. Alternatively, download the SDK packages and manually add them to your project.

Example of using SDK for Python

The following example uses SDK for Python to describe how to create a resource account:

#! /usr/bin/env python
#coding = utf - 8
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkresourcemanager.request.v20200331.CreateResourceAccountRequest import CreateResourceAccountRequest
# Construct an Alibaba Cloud client to send requests.
# When you construct the client, configure the AccessKey ID and AccessKey secret.
# Resource Management is a global service. However, the Resource Management API endpoint is located in the China (Shanghai) region. Therefore, set the region to cn-shanghai.
client = AcsClient('<accessKeyId>', '<accessSecret>', 'cn-shanghai')
# Construct the request object.
request = CreateResourceAccountRequest()
# Specify the required parameters.
request.set_accept_format('json')
request.set_DisplayName("test")
# Issue the request and obtain a response.
response = client.do_action_with_exception(request)
#python2: print(response)
print(str(response, encoding = 'utf-8'))