This topic describes how to install and use CloudMonitor SDK for Python.

Background information

  • To use CloudMonitor SDK for Python, you must install the core library of Alibaba Cloud SDK for Python (aliyun-python-sdk-core) and the core library of CloudMonitor SDK for Python (aliyun-python-sdk-cms).
  • Alibaba Cloud provides OpenAPI Explorer to simplify API usage. You can use OpenAPI Explorer to debug API operations and dynamically generate SDK sample code.
  • For more information about the CloudMonitor API, see List of API operations by function.

Install CloudMonitor SDK for Python

You can download the installation packages of the SDKs for Python from the following links:

Sample code

The following sample code provides an example on how to use CloudMonitor SDK for Python to call the CloudMonitor API operation DescribeMetricList. For other operations, you can use OpenAPI Explorer to debug the operations and obtain sample code.

For more information about the request parameters of the DescribeMetricList operation, see DescribeMetricList.

#!/usr/bin/env python

from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkcms.request.v20190101.DescribeMetricListRequest import DescribeMetricListRequest

// Construct an Alibaba Cloud client to initiate requests. 
// When you construct the client, specify your AccessKey ID and AccessKey secret. 
client = AcsClient('<accessKeyId>', '<accessSecret>', 'cn-hangzhou')
# Construct a request. 
request = DescribeMetricListRequest()
# Specify the request parameters. 
# Initiate the request and obtain a response. 
response = client.do_action_with_exception(request)
# python2:  print(response)
print(str(response, encoding='utf-8'))