1.happybase
- 访问使用的是thrift,因此必须开启thrift(hbase thrift start)
- 如果hbase-site.xml的hbase.regionserver.thrift.http设置为true,则该方式无法访问。会有No protocol version 的错误
connection = happybase.Connection(host="localhost",port=9090)
print(connection.tables())
connection.close()
2.hbase-python
import hbase
zk = 'localhost:2181'
if __name__ == '__main__':
with hbase.ConnectionPool(zk).connect() as conn:
table = conn['stu']['test']
row = table.get('1')
print(row)
exit()
if __name__ == '__main__':
with hbase.ConnectionPool(zk).connect() as conn:
table = conn['stu']['test']
for row in table.scan():
print(row)
exit()
if __name__ == '__main__':
with hbase.ConnectionPool(zk).connect() as conn:
table = conn['stu']['test']
table.put(hbase.Row(
'0001', {
'cf:name': b'Lily',
'cf:age': b'20'
}
))
exit()
if __name__ == '__main__':
with hbase.ConnectionPool(zk).connect() as conn:
table = conn['mytest']['videos']
table.write_file(video_file)
exit()