All Products
Search
Document Center

Server Migration Center:Python SDK usage example

Last Updated:Jun 20, 2026

This topic explains how to set up a Python environment and use sample code to call API operations. It covers installation and helps you quickly build and integrate a cloud service.

Prerequisites

  • You have downloaded and installed Python 3.

    Open a terminal and run python --version to check your Python version.

  • You have a Python code editor installed.

    This topic uses PyCharm as an example.

  • You have obtained an AccessKey pair.

    You must use an AccessKey pair to authenticate your API requests. An AccessKey pair consists of an AccessKey ID and an AccessKey Secret. For information about how to create and obtain an AccessKey pair, see Create an AccessKey pair.

Procedure

Step 1: Configure environment variables

To avoid the security risk of hardcoding your AccessKey pair, this example uses environment variables to manage it. For more information, see Configure environment variables on Linux, macOS, and Windows.

Step 2: Install dependencies

Run the following commands to install dependencies.

Note

If pip is not installed in your environment, see the pip official website for installation instructions.

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 SDK sample project

  1. Go to the API debugging page in OpenAPI Portal and select an API operation in the left-side navigation pane.

    This topic uses the DescribeSourceServers API operation as an example.

  2. On the left-side Parameters tab, select a region and specify the required parameters. Refer to the Documentation tab on the right for details about the API operation, its parameters, and important notes, such as billing information.

  3. On the right-side SDK Sample tab, select Python and click Download Complete Project. Decompress the downloaded SDK project on your local machine.

    Note

Step 4: Import the decompressed project

  1. Open PyCharm.

  2. In the top menu bar, choose .

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

Step 5: Run the SDK sample code

  1. In the left-side navigation pane of PyCharm, open the Python SDK sample code file.

  2. In the top menu bar, choose .

  3. View the output.

    C:\Demo\python-sdk\venv\Scripts\python.exe C:/Demo/python-sdk/alibabacloud_sample...
    [LOG] {"headers": {"date": "Fri, 30 Jun 2023 05:26:00 GMT", "content-type": "appl...}}
    Process finished with exit code 0

The SDK also supports advanced settings, such as HTTPS requests, proxies, timeouts, and retry mechanisms. For more information, see Advanced configuration.