All Products
Search
Document Center

Tair (Redis® OSS-Compatible):Use Alibaba Cloud SDK for Python to call an API operation

Last Updated:May 28, 2025

This topic describes how to use Alibaba Cloud SDK for Python to call the DescribeInstancesOverview operation of Tair (Redis OSS-compatible). You can call this operation to query the basic information about Tair (Redis OSS-compatible) instances.

View the API documentation

Before you call a Tair API operation, we recommend that you read the List of operations by function topic to learn the limits and parameters associated with the operation.

Create a RAM user and grant permissions to the RAM user

If you have created a Resource Access Management (RAM) user and granted permissions to the user, you can skip this step.

  1. Create a RAM user.

    1. Log on to the RAM console, go to the Users page, and then click Create User.

    2. Set the Logon Name parameter to redis-openapi-operator and select Using permanent AccessKey to access for the Access Mode parameter.

    3. Click OK and save the AccessKey ID and AccessKey secret.

  2. Grant permissions to the RAM user.

    1. Go to the Users page, find the RAM user that you created, and then click Add Permissions in the Actions column.

    2. In the panel that appears, enter AliyunKvstore in the search box and then select the AliyunKvstoreReadOnlyAccess policy.

      Note

      The AliyunKvstoreReadOnlyAccess policy provides read permissions on Tair instances, and the AliyunKvstoreFullAccess policy provides read and write permissions on Tair instances. You can also specify a custom policy based on your business requirements. For more information, see Identity management.

    3. Click Grant permissions.

Call an API operation

This section describes how to use Alibaba Cloud SDK for Python to call a Tair API operation. You can use SDKs for other programming languages in a similar way. For more information, see Tair (Redis OSS-compatible) SDKs.

Prepare a Python environment

Download and install Python 3. If you have installed Python, run the python --version command to query the Python version.

Configure environment variables

Configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.

  • If you use the Linux or macOS operating system, replace <access_key_id> and <access_key_secret> in the following commands with your AccessKey ID and AccessKey secret. Then, run the commands on your device.

    export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id>
    export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>
  • If you use a Windows operating system, create a file to add the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables and set the variables to your AccessKey ID and AccessKey secret. Then, restart the Windows operating system.

Install dependencies

Run the following commands in sequence on your device to install environment dependencies:

pip install alibabacloud_credentials
pip install alibabacloud_r_kvstore20150101
pip install alibabacloud_tea_console

Download the sample code

  1. Go to the page of the DescribeInstancesOverview operation in the OpenAPI portal.

  2. On the left-side Parameters tab, specify the parameters. In this example, RegionId is set to cn-hangzhou.

  3. On the right-side SDK Sample Code tab, select Python for the Languages parameter and click Download Project to download the package of sample code.

  4. Decompress the package and go to the alibabacloud_sample directory.

Run the sample code

Run the following command:

python sample.py

Sample output:

[
    LOG
]{
    "headers": {
        "date": "Tue, 04 Jul 2023 10:03:39 GMT",
        "content-type": "application/json;charset=utf-8",
        "content-length": "1665",
        "connection": "keep-alive",
        "keep-alive": "timeout=25",
        "vary": "Accept-Encoding",
        "access-control-allow-origin": "*",
        "access-control-expose-headers": "*",
        "x-acs-request-id": "F2F4B6CB-3C03-51A0-9300-F78BC94E****",
        "x-acs-trace-id": "4d9ceb1f6cb98086cd8333f0bb30****",
        "etag": "1YlaXvHZ3H5CjZic1Oeo****"
    },
    "statusCode": 200,
    "body": {
        "Instances": [
            {
                "ArchitectureType": "standard",
                "Capacity": 4096,
                "ChargeType": "PostPaid",
                "ConnectionDomain": "r-bp1u7sm6mp6h83****.redis.rds.aliyuncs.com",
                "CreateTime": "2023-02-07T05:49:56Z",
                "EngineVersion": "6.0",
                "InstanceClass": "redis.shard.large.ce",
                "InstanceId": "r-bp1u7sm6mp6h83****",
                "InstanceName": "",
                "InstanceStatus": "Normal",
                "InstanceType": "Redis",
                "NetworkType": "VPC",
                "RegionId": "cn-hangzhou",
                "ResourceGroupId": "rg-acfmz7u4zzr****",
                "VSwitchId": "vsw-bp1ah4djy7ghm3ump****",
                "VpcId": "vpc-bp1p5zk2l6ixtgx6v****",
                "ZoneId": "cn-hangzhou-h"
            },
            {
                "ArchitectureType": "rwsplit",
                "Capacity": 2048,
                "ChargeType": "PostPaid",
                "ConnectionDomain": "r-bp1qsslcssrjeb****.redis.rds.aliyuncs.com",
                "CreateTime": "2023-02-07T05:53:33Z",
                "EngineVersion": "6.0",
                "InstanceClass": "tair.rdb.with.proxy.2g",
                "InstanceId": "r-bp1qsslcssrjeb****",
                "InstanceName": "",
                "InstanceStatus": "Normal",
                "InstanceType": "tair_rdb",
                "NetworkType": "VPC",
                "RegionId": "cn-hangzhou",
                "ResourceGroupId": "rg-acfmz7u4zzr****",
                "VSwitchId": "vsw-bp1ah4djy7ghm3ump****",
                "VpcId": "vpc-bp1p5zk2l6ixtgx6v****",
                "ZoneId": "cn-hangzhou-h"
            }
        ],
        "RequestId": "F2F4B6CB-3C03-51A0-9300-F78BC94EE283",
        "TotalCount": 2
    }
}