All Products
Search
Document Center

Server Migration Center:Use SMC SDK for Python

Last Updated:May 23, 2024

This topic describes how to install the environment for using Server Migration Center (SMC) SDK for Python and run the sample code to call an API operation.

Prerequisites

  • Python 3 is downloaded and installed.

    Run the python --version command on the terminal to check the Python version.

  • A Python code editor is downloaded.

    In this example, PyCharm is used.

  • An AccessKey pair is obtained.

    When you call an API operation, you must use an AccessKey pair to complete identity authentication. An AccessKey pair consists of an AccessKey ID and an AccessKey secret. For more information about how to create an AccessKey pair, see Create an AccessKey pair.

Procedure

Step 1: Configure environment variables

In this example, environment variables are configured to manage the AccessKey pair. This prevents security risks that are caused by hard-coding the AccessKey pair into your business code. For more information, see Configure environment variables in Linux, macOS, and Windows.

Step 2: Install dependencies

Use one of the following methods to install the dependencies:

Note

If pip is not installed, visit the official website of pip to download and install pip. For more information, see Installation.

pip install alibabacloud_credentials
pip install alibabacloud_smc20190601==1.0.2
pip install alibabacloud_tea_console==0.0.1
pip install alibabacloud_tea_util==0.3.11
pip install alibabacloud_tea_openapi==0.3.8

Step 3: Download the sample SDK project

  1. Go to the

    API debugging page of OpenAPI Portal. In the left-side navigation pane, select an API operation that you want to call.

    In this example, the DescribeSourceServers operation is selected.

  2. In the DescribeSourceServers pane, specify the Region parameter and click the Parameters tab. On the Parameters tab, specify the request parameters. When you specify the request parameters of the API operation, you can refer to the information on the Document tab on the right. On this tab, you can also learn about the limits and usage notes of an API operation, especially the billing information, and the specific meaning and usage of each parameter in the request.

  3. On the SDK Sample Code tab, select Python for the Languages parameter and click Download Project.

    Note

    image.png

Step 4: Import the decompressed project

  1. Open PyCharm.

  2. In the top navigation bar, choose File > New > Project from Existing Sources....

    image.png

  3. In the dialog box that appears, select the decompressed SDK project file.

Step 5: Run the SDK sample code

  1. In the left-side navigation pane of PyCharm, open the SDK project file.

  2. In the top navigation bar, choose Run > Run... to run the sample code.

    image.png

  3. View the result.

    image.png

You can also configure an HTTPS request, a proxy, a timeout period, and a retry mechanism in the SDK for Python based on your business requirements. For more information, see Configure an HTTPS request.