Python 连接 Hbase happybase

1. 安装thrift

brew install thrift

2.启动thrift

./hbase-daemon.sh start thrift

3.安装依赖python 库

 

pip install thrift
pip install hbase-thrift
pip install happybase

这边用的是happybase 这个库,https://happybase.readthedocs.io/en/latest/user.html 去这了解更多。

import happybase
#连接
connection = happybase.Connection('localhost')
connection.open()

# connection.create_table('mytable', {'name' : dict(max_versions=5), 'course':dict()})
#打印所有的表
print(connection.tables())
table = connection.table('Score')
row = table.row(b'95001')
print(row[b'course:Math'])

#插入数据
table.put(b'95002', {b'course:Math':b'65', b'course:English':b'77'})

http://www.waitingfy.com/archives/4029

4029

Leave a Reply

Name and Email Address are required fields.
Your email will not be published or shared with third parties.