Connect to HBase in Python via HappyBase

Raymond Raymond event 2022-03-22 visibility 3,000
more_vert
Connect to HBase in Python via HappyBase
HappyBase is a Python package that can be used to connect to your HBase environment. You can use it easily to insert data, delete data and query data, etc. 

Prerequisites

If you don't have a HBase environment to work with, please follow one of the following articles to install HBase:

Install HappyBase package

Use the following command to install HappyBase Python package:

pip install happybase
# or
pip3 install happybase

Connect to HBase

After you installed HBase, make sure you start both HBase service and also thrift service:

bin/start-hbase.sh
bin/hbase-daemon.sh start thrift

By default, the thrift service listens on port 9090.

infoUse sudo if the service doesn't start properly.

Now create a Python script named test-hbase.py with the following content:

import happybase
connection = happybase.Connection('127.0.0.1',9090)
table = connection.table('test_table')
row = table.row(b'row1')
print(row[b'cf:a'])

The scripts connect to the Thrift service in my WSL local HBase standalone instance. Table test_table was created as part of the installation tutorial. 

The output looks like the following screenshot:

20220322110014-image.png

It print out value b'value1'.

References

To learn more about HappyBase package, refer to HappyBase - HappyBase 1.2.0 documentation.


More from Kontext
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts