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 HBase in WSL - Pseudo-Distributed Mode
- Install HBase in WSL - Standalone Mode (Follow this if you don't want to configure Hadoop).
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.
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:
b'value1'
.References
To learn more about HappyBase
package, refer to HappyBase - HappyBase 1.2.0 documentation.