All Products
Search
Document Center

Database Autonomy Service:Use DAS SDK for Python

Last Updated:Mar 28, 2026

This guide shows how to use the Database Autonomy Service (DAS) SDK for Python to call the GetInstanceInspections API operation, which retrieves inspection and scoring results for a database instance.

Prerequisites

Before you begin, ensure that you have:

How it works

The example in this guide does the following:

  1. Authenticates using credentials from environment variables.

  2. Calls GetInstanceInspections to query completed inspection and scoring tasks within a specified time range.

  3. Returns a paginated list of inspection results, including scores, instance details, and diagnostic data.

For a full list of DAS API operations, see the DAS API reference. For SDKs in other languages, see DAS SDK.

Set up a RAM user

Skip this section if you already have a Resource Access Management (RAM) user with DAS permissions.

  1. Create a RAM user.

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

    2. Set Logon Name to das-openapi-operator and set Access Mode to Using permanent AccessKey to access.

    3. Click OK. Save the AccessKey ID and AccessKey secret displayed after creation.

  2. Grant permissions to the RAM user.

    1. On the Users page, find the RAM user and click Add Permissions in the Actions column.

    2. Search for DAS and select AliyunHDMReadOnlyAccess.

      Note

      AliyunHDMReadOnlyAccess grants read-only access to DAS. For full read and write access, select AliyunHDMFullAccess instead. To create a custom policy with specific permissions, see Create custom policies.

    3. Click Grant permissions.

Configure environment variables

Store your credentials as environment variables to avoid hardcoding sensitive values in your code.

Linux or macOS:

export ALIBABA_CLOUD_ACCESS_KEY_ID=<ACCESS_KEY_ID>
export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<ACCESS_KEY_SECRET>

Windows (Command Prompt):

set ALIBABA_CLOUD_ACCESS_KEY_ID=<ACCESS_KEY_ID>
set ALIBABA_CLOUD_ACCESS_KEY_SECRET=<ACCESS_KEY_SECRET>

Windows (PowerShell):

$env:ALIBABA_CLOUD_ACCESS_KEY_ID = "<ACCESS_KEY_ID>"
$env:ALIBABA_CLOUD_ACCESS_KEY_SECRET = "<ACCESS_KEY_SECRET>"
Note

The set and $env: commands are session-scoped — the variables are lost when you close the terminal or restart Windows. To set persistent environment variables on Windows, use the Windows System Properties dialog (Control Panel > System > Advanced system settings > Environment Variables) or create a file that sets these variables and restart Windows.

Replace <ACCESS_KEY_ID> and <ACCESS_KEY_SECRET> with the values you saved when creating the RAM user.

Install the SDK

We recommend using a virtual environment to avoid dependency conflicts with other packages on your system:

python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

Then install the DAS Python SDK:

pip install alibabacloud_das20200116==2.4.2

Call the API

Get the sample code

The sample code is auto-generated by OpenAPI Explorer based on the parameters you configure.

  1. Go to the GetInstanceInspections page in OpenAPI Explorer.

  2. On the Parameters tab, set the following parameters. This example queries inspections on an ApsaraDB RDS for MySQL instance.

    ParameterExample valueNotes
    EngineMySQL
    StartTime1718776527000UNIX timestamp in milliseconds. Set this to the actual start of your query range.
    EndTime1718776827000UNIX timestamp in milliseconds. Set this to the actual end of your query range. If no inspections completed within the range, run an inspection manually and retry.
    InstanceAreaRDS
    PageNo1
    PageSize10
  3. On the SDK Sample Code tab on the right, select Python for the Languages parameter and click Download Project.

  4. Extract the downloaded package and go to the alibabacloud_sample directory.

Run the sample code

python sample.py

Understand the response

A successful call returns HTTP status code 200. The response body has the following structure:

FieldDescription
Data.ListArray of inspection records. Each record contains instance metadata, diagnostic data, and a score.
Data.List[].ScoreInspection score for the instance.
Data.List[].StateTask state.
Data.List[].TaskTypeTask type.
Data.List[].InstanceInstance details: engine, version, region, CPU, memory, storage, and network type.
Data.List[].DataDiagnostic data: slow SQL count, deadlock detection, active sessions, big transactions, and storage usage.
Data.PageNoCurrent page number.
Data.PageSizeNumber of records per page.
Data.TotalTotal number of matching records.

Sample response:

{
  "headers": {
    "date": "Wed, 19 Jun 2024 06:24:10 GMT",
    "content-type": "application/json;charset=utf-8",
    "content-length": "1428",
    "connection": "keep-alive",
    "keep-alive": "timeout=25",
    "vary": "Accept-Encoding",
    "access-control-allow-origin": "*",
    "access-control-expose-headers": "*",
    "x-acs-request-id": "B576DACC-D08A-5058-8843-E613CBF474CF",
    "x-acs-trace-id": "2fb5b5b76565ce67233288b9369f6d96",
    "etag": "1rcNeDQg43APurk7PohefuQ8"
  },
  "statusCode": 200,
  "body": {
    "Code": 200,
    "Data": {
      "List": [
        {
          "AutoFunction": {
            "AutoIndex": 1,
            "AutoLimitedSql": 0,
            "AutoResourceOptimize": 2,
            "AutoScale": 0,
            "EventSubscription": 0
          },
          "Data": {
            "hasDeadLock": false,
            "slowSqlCount": 0,
            "exceptionTableMap": {},
            "spaceItem": {
              "valid": true,
              "current": 0.16416015625,
              "avg": 0.16416015625,
              "min": 0.16416015625,
              "max": 0.16416015625
            },
            "maxIops": 3100,
            "bigTransactionCount": 0,
            "cpu": 2,
            "isRds": true,
            "storage": 20,
            "lastHourRate": 0.0,
            "lastDayCount": 0,
            "lastHourCount": 0,
            "slowSqlList": [],
            "lastDayRate": 0.0,
            "activeSessions": [],
            "enable": false,
            "bigTransactionList": [],
            "bigSessionList": [
              {
                "User": "system user",
                "Command": "Query",
                "State": "Replica has read all relay log; waiting for more updates",
                "active": false,
                "Host": "",
                "Time": 24,
                "Id": 61,
                "Info": "",
                "db": ""
              }
            ],
            "tableStats": [],
            "bigSessionCount": 1,
            "spaceUsage": 0.16416015625,
            "availableDays": 76
          },
          "EnableDasPro": 0,
          "EndTime": 1718726400000,
          "GmtCreate": 1718776692000,
          "Instance": {
            "AccountId": "1648821913965368",
            "Category": "standard",
            "Cpu": "2",
            "Engine": "MySQL",
            "EngineVersion": "8.0",
            "InstanceArea": "RDS",
            "InstanceClass": "mysql.n2m.medium.2c",
            "InstanceId": "rm-bp1s6jtqtr41m****",
            "Memory": 4096,
            "NetworkType": "VPC",
            "Region": "cn-hangzhou",
            "Storage": 20,
            "Uuid": "hdm_6d00b701adcb484d5fa4d2800dc0****",
            "VpcId": "vpc-bp1ov7as4yvz4kxei****"
          },
          "Score": 100,
          "StartTime": 1718640000000,
          "State": 2,
          "TaskType": 1
        }
      ],
      "PageNo": 1,
      "PageSize": 10,
      "Total": 1
    },
    "Message": "Successful",
    "RequestId": "B576DACC-D08A-5058-8843-E613CBF474CF",
    "Success": true
  }
}

What's next