All Products
Search
Document Center

ApsaraDB for HBase:Multi-language API access

Last Updated:Mar 30, 2026

Use Thrift to connect to ApsaraDB for HBase Performance-enhanced Edition clusters from Python, Go, C++, Node.js, or PHP.

Prerequisites

Before you begin, ensure that you have:

How it works

ApsaraDB for HBase Performance-enhanced Edition uses HTTP at the Thrift transport layer. All clients must use THttpClient — not the standard socket transport — to connect. For Thrift 2, you must specify the username and the password as custom HTTP headers in the THttpClient instance.

Thrift 1 vs. Thrift 2

Feature Thrift 1 Thrift 2
Authentication Not supported Required (username + password)
Max connections per core node 1,000
Transport THttpClient THttpClient (HTTP only)

Use Thrift 2 for new integrations. Thrift 1 lacks authentication support and is unsuitable for clusters with ACL enabled.

Set up Thrift

Install the Thrift compiler

Most languages can install the Thrift library directly via their package manager. Download the compiler only if you need to regenerate interface definition files from Hbase.thrift.

Package manager (recommended):

Language Command
Python pip install thrift
Go import "github.com/apache/thrift/lib/go/thrift" in your Go module

Manual compiler install: Download thrift-0.12.0.tar.gz and follow the Thrift installation guide.

Generate the interface definition file

  1. Download the Thrift 2 definition file for ApsaraDB for HBase.

  2. Extract the Thrift compiler package and run the following command from the extracted directory to generate language-specific bindings:

    thrift --gen <language> Hbase.thrift

    Examples:

    thrift --gen py Hbase.thrift
    thrift --gen cpp Hbase.thrift
    thrift --gen php Hbase.thrift

Initialize a client

The following example uses Python. Apply the same pattern to other languages: create a THttpClient, add the authentication headers, wrap it in TBinaryProtocol, and pass the protocol to the THBaseService.Client.

# -*- coding: utf-8 -*-
# Install the Thrift library: pip install thrift
from thrift.protocol import TBinaryProtocol
from thrift.transport import THttpClient

# Generated by: thrift --gen py Hbase.thrift
from hbase import THBaseService
from hbase.ttypes import (
    TColumnValue, TColumn, TTableName, TTableDescriptor,
    TColumnFamilyDescriptor, TNamespaceDescriptor,
    TGet, TPut, TScan
)

# Replace <host> with your cluster endpoint.
url = "http://<host>:9190"

# THttpClient is required — the HBase Thrift server uses HTTP transport,
# not the standard socket transport.
transport = THttpClient.THttpClient(url)

# Pass credentials as custom HTTP headers. Thrift 2 requires the username and password.
headers = {
    "ACCESSKEYID": "<your-username>",       # Cluster username
    "ACCESSSIGNATURE": "<your-password>",   # Cluster password
}
transport.setCustomHeaders(headers)

# TBinaryProtocolAccelerated uses a C extension for faster serialization
# when available, and falls back to the pure-Python implementation.
protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport)

# Create the HBase client using the configured protocol.
client = THBaseService.Client(protocol)

# Open the connection before making any calls.
transport.open()

# Your HBase operations go here.

# Close the transport when done to release the connection.
transport.close()

Placeholders:

Placeholder Description
<host> Your cluster endpoint (without the http:// prefix)
<your-username> The cluster username
<your-password> The cluster password
Note

Thrift 1 does not support authentication. Use Thrift 2 (as shown above) when your cluster requires credentials.

Sample code

Complete, runnable client examples for each language are available on GitHub. Each repository includes the Thrift definition files and any language-specific dependencies.

Language Link
Python Download sample code
Go Download sample code
C++ Download sample code
Node.js Download sample code
PHP Download sample code

What's next