This topic describes how to use the ApsaraDB for HBase API for a non-Java language, such as C++, Python, and Go, to connect to and use LindormTable.
Prerequisites
The Thrift installation package is downloaded.
The Thrift2 definition file for ApsaraDB for HBase is downloaded.
The LindormTable endpoint that is displayed after Access by Using HBase non-Java API on the Wide Table Engine tab of the Lindorm console is obtained. For more information, see View endpoints.
Use the ApsaraDB for HBase API for a non-Java language, such as Python, to connect to LindormTable
For more information about how to install Thrift by using the Thrift installation package, see the Apache Thrift official documentation. You can perform the following steps to use Thrift to connect to LindormTable:
Execute the following statement to use the Thrift2 definition file for ApsaraDB for HBase to generate an interface definition language (IDL) file in the corresponding language:
thrift --gen <language> Hbase.thrift
NoteThe language parameter specifies the programming language that you want to use. You can set this parameter to python, php, cpp, or py.
Sample statement:
thrift --gen python Hbase.thrift
Create a client to connect to LindormTable.
The Thrift server in Lindorm uses HTTP in the transport layer. The ThttpClient of Thrift is required when you create a client. The method of creating the client varies based on the languages. If the Access Control List (ACL) is enabled, specify the username and password in two headers in the ThttpClient for authentication. The username and password are not required if ACL is disabled. Thrift allows you to call a function for a language to specify a custom header in ThttpClient. In the following example, Python is used. You can execute the following statements to create a client and connect to LindormTable:
# -*- coding: utf-8 -*- # You can run the pip install thrift command to generate the following two modules: from thrift.protocol import TBinaryProtocol from thrift.transport import THttpClient # You can run the thrift --gen py hbase.thrift command to generate the following two modules: from hbase import THBaseService from hbase.ttypes import TColumnValue, TColumn, TTableName, TTableDescriptor, TColumnFamilyDescriptor, TNamespaceDescriptor, TGet, TPut, TScan # Specify the endpoint of LindormTable. url = "http://ld-bp17j28j2y7pm****-proxy-lindorm.lindorm.rds.aliyuncs.com:9190" transport = THttpClient.THttpClient(url) headers = {} # Specify the username. headers["ACCESSKEYID"]="testuser"; # Specify the password that corresponds to the username. headers["ACCESSSIGNATURE"]="password" transport.setCustomHeaders(headers) protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport) client = THBaseService.Client(protocol) transport.open() # Close the connection. transport.close()