Python操作Hbase

参考链接https://happybase.readthedocs.io/en/latest/news.html#happybase-0-9

1.安装依赖包

pip install happybase
pip install thrift

2.连接Hbase

import happybase
connection = happybase.Connection('cdh04')
#注意cdh04为Thrift server地址
print (connection.tables())

Python操作Hbase_第1张图片

3.happybase的使用

3.1建立连接

import happybase
connection = happybase.Connection('cdh04')

当connection被创建的时候,默认自动与Hbase建立socket连接的
若不想自动与Hbase建立socket连接,可以将autoconnect参数设置为False
connection = happybase.Connection('cdh04', autoconnect=False)
然后手动与Hbase建立socket连接
connection.open() 

3.2查看可用的table

print (connection.tables())

3.2创建table
创建table名字Jacson_Bai包含3个列族:INFO、NAME、SOURCE
connection.create_table(
    'Jacson_Bai',
    {
        'INFO': dict(max_versions=3),
        'NAME': dict(max_versions=1, block_cache_enabled=False),
        'SOURCE': dict(),
    }
)

Python操作Hbase_第2张图片

你可能感兴趣的:(Python,爬虫系列)