Happybase是Python通过Thrift访问HBase的库,方便快捷。
基本使用
import happybase
connection = happybase.Connection('hostname')
table = connection.table('table-name')
table.put('row-key', {'family:qual1': 'value1', 'family:qual2': 'value2'})
row = table.row('row-key')
print row['family:qual1'] # prints 'value1'
for key, data in table.rows(['row-key-1', 'row-key-2']):
print key, data # prints row key and data for each row
for key, data in table.scan(row_prefix='row'):
print key, data # prints 'value1' and 'value2'
row = table.delete('row-key')
链接
# lazy connection
connection = happybase.Connection('somehost', autoconnect=False)
# and before first use:
connection.open()
# show all tables
print connection.tables()
# Using table namespace
connection = happybase.Connection('somehost', table_prefix='myproject')
表
connection.create_table(
'mytable',
{'cf1': dict(max_versions=10),
'cf2': dict(max_versions=1, block_cache_enabled=False),
'cf3': dict(), # use defaults
}
)
table = connection.table('mytable')