All Products
Search
Document Center

Hologres:SDK for Python

Last Updated:Mar 26, 2026

Hologres SDK for Python lets you manage Hologres instances programmatically — create, query, and configure instances through the management API.

Use OpenAPI Explorer to browse all available API operations and generate SDK sample code interactively.

Prerequisites

Before you begin, ensure that you have:

Install the SDK

Run the following pip command to install the SDK:

pip install alibabacloud_hologram20220601==1.0.5

For other installation methods, see SDK installation options and Get started with Alibaba Cloud Darabonba SDK for Java.

Quick start

The following example queries instance details using the GetInstance API operation. All steps run sequentially: import the SDK, configure credentials, initialize a client, and call the API.

import os
from alibabacloud_hologram20220601.client import Client as Hologram20220601Client
from alibabacloud_tea_openapi import models as open_api_models

# Configure credentials from environment variables.
# Storing credentials in code risks exposing them if the project is shared.
# For higher security, use Security Token Service (STS) instead.
config = open_api_models.Config(
    access_key_id=os.environ['ALIBABA_CLOUD_USER'],
    access_key_secret=os.environ['ALIBABA_CLOUD_PASSWORD']
)

# Set the endpoint for your region.
# For a full list of endpoints, see Hologres regions:
# https://api.aliyun.com/product/Hologram#endpoint
config.endpoint = 'hologram.cn-hangzhou.aliyuncs.com'

client = Hologram20220601Client(config)

# Call GetInstance to query the details of an instance.
# For Hologres V1.0.3 and later, pass only the instance ID.
response = client.get_instance('<your-instance-id>')
print(response)
Note: For Hologres earlier than V1.0.3, pass a GetInstanceRequest object as the second argument: client.get_instance('<your-instance-id>', get_instance_request). The GetInstanceRequest parameter is not supported in V1.0.3 and later.
Placeholder Description
<your-instance-id> Your Hologres instance ID

Step-by-step guide

Use this section if you want to understand each step in detail before running the full example.

1. Import the SDK

from alibabacloud_hologram20220601.client import Client as Hologram20220601Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_hologram20220601 import models as hologram_20220601_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient

2. Configure credentials and endpoint

Store your AccessKey ID and AccessKey secret in environment variables, then reference them in code. For the endpoint that matches your region, see Hologres regions.

config = open_api_models.Config(
    # AccessKey ID from environment variable
    access_key_id=os.environ['ALIBABA_CLOUD_USER'],
    # AccessKey secret from environment variable
    access_key_secret=os.environ['ALIBABA_CLOUD_PASSWORD']
)
# Set your region endpoint
config.endpoint = 'hologram.cn-hangzhou.aliyuncs.com'
Note: Configure ALIBABA_CLOUD_USER and ALIBABA_CLOUD_PASSWORD in your runtime environment before running the code. If project code is leaked, hardcoded credentials expose all resources in your account. For stronger protection, use Security Token Service (STS).

3. Initialize the client

client = Hologram20220601Client(config)

4. Create a request object

This step applies only to Hologres earlier than V1.0.3. For V1.0.3 and later, skip this step — GetInstanceRequest is not supported.

from alibabacloud_hologram20220601.models import GetInstanceRequest
get_instance_request = GetInstanceRequest()

5. Call the API and view the response

# Hologres V1.0.3 and later:
response = client.get_instance('your_instanceId')
print(response)

# Hologres earlier than V1.0.3:
response = client.get_instance('your_instanceId', get_instance_request)
print(response)

Full working example

The following is a complete example that queries instance details in Hologres V1.0.3 or later. It includes both synchronous and asynchronous variants.

# -*- coding: utf-8 -*-
import sys
import os

from typing import List

from alibabacloud_hologram20220601.client import Client as Hologram20220601Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient


class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client(
        access_key_id: str,
        access_key_secret: str,
    ) -> Hologram20220601Client:
        """
        Use your AccessKey ID and AccessKey secret to initialize the client.
        @param access_key_id:
        @param access_key_secret:
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            # Required. Specify your AccessKey ID.
            access_key_id=access_key_id,
            # Required. Specify your AccessKey secret.
            access_key_secret=access_key_secret
        )
        # Specify the endpoint.
        config.endpoint = f'hologram.cn-hangzhou.aliyuncs.com'
        return Hologram20220601Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        # Make sure that the ALIBABA_CLOUD_USER and ALIBABA_CLOUD_PASSWORD environment variables are configured for the runtime environment.
        # If the project code is leaked, the AccessKey pair may be leaked and security issues may occur on all resources of your account. The following sample code is for reference only. We recommend that you use Security Token Service (STS), which provides higher security.
        client = Sample.create_client(os.environ['ALIBABA_CLOUD_USER'],
                                      os.environ['ALIBABA_CLOUD_PASSWORD'])
        try:
            # After you copy and run the sample code, obtain the return value of the API operation.
            client.get_instance('instanceId')
        except Exception as error:
            # Print the error if necessary.
            print("error: ", error)


    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        # Make sure that the ALIBABA_CLOUD_USER and ALIBABA_CLOUD_PASSWORD environment variables are configured for the runtime environment.
        # If the project code is leaked, the AccessKey pair may be leaked and security issues may occur on all resources of your account. The following sample code is for reference only. We recommend that you use STS, which provides higher security.
        client = Sample.create_client(os.environ['ALIBABA_CLOUD_USER'],
                                      os.environ['ALIBABA_CLOUD_PASSWORD'])
        try:
            # After you copy and run the sample code, obtain the return value of the API operation.
            await client.get_instance('instanceId')
        except Exception as error:
            # Print the error if necessary.
            print("error: ", error)


if __name__ == '__main__':
    Sample.main(sys.argv[1:])

A successful response looks like:

{
  "RequestId": "1E8EFA1E-xxxx-xxxx-xxxx-xxxx",
  "Instance": {
    "SuspendReason": "",
    "ZoneId": "cn-hangzhou-h",
    "InstanceId": "hgpostcn-cn-xxxxxxxxxxxx",
    "InstanceChargeType": "PostPaid",
    "Memory": 64,
    "InstanceOwner": "1239xxxxxxxxxxxx",
    "ColdStorage": 0,
    "Cpu": 16,
    "EnableHiveAccess": false,
    "InstanceName": "xxxx",
    "ComputeNodeCount": 1,
    "Endpoints": [
      {
        "Type": "Intranet",
        "Endpoint": "hgpostcn-cn-xxxxxxxxxxxx-cn-hangzhou-internal.hologres.aliyuncs.com:80",
        "Enabled": true
      },
      {
        "Type": "VPCSingleTunnel",
        "Endpoint": "hgpostcn-cn-xxxxxxxxxxxx-cn-hangzhou-vpc-st.hologres.aliyuncs.com:80",
        "VpcId": "vpc-xxxxxxxxxxxxxxxx",
        "VSwitchId": "vsw-xxxxxxxxxxxxxxxx",
        "Enabled": true,
        "VpcInstanceId": "hgpostcn-cn-xxxxxxxxxxxx-frontend-st"
      }
    ],
    "AutoRenewal": false,
    "Version": "r1.3.43",
    "InstanceStatus": "Running",
    "CommodityCode": "hologram_postpay_public_cn",
    "CreationTime": "2023-04-12T03:41:59.036Z",
    "InstanceType": "Standard",
    "Disk": 0,
    "Tags": [
      {
        "Value": "rg-xxxxxxxxxxxx",
        "Key": "acs:rm:rgId"
      }
    ]
  },
  "HttpStatusCode": 200,
  "Success": true
}