Happybase的基本使用

Happybase是Python通过Thrift访问HBase的库,方便快捷。

基本使用


  1. import happybase
  2. connection = happybase.Connection('hostname')
  3. table = connection.table('table-name')
  4. table.put('row-key', {'family:qual1': 'value1', 'family:qual2': 'value2'})
  5. row = table.row('row-key')
  6. print row['family:qual1'] # prints 'value1'
  7. for key, data in table.rows(['row-key-1', 'row-key-2']):
  8. print key, data # prints row key and data for each row
  9. for key, data in table.scan(row_prefix='row'):
  10. print key, data # prints 'value1' and 'value2'
  11. row = table.delete('row-key')

链接


  1. # lazy connection
  2. connection = happybase.Connection('somehost', autoconnect=False)
  3. # and before first use:
  4. connection.open()
  5. # show all tables
  6. print connection.tables()
  7. # Using table namespace
  8. connection = happybase.Connection('somehost', table_prefix='myproject')


  1. connection.create_table(
  2. 'mytable',
  3. {'cf1': dict(max_versions=10),
  4. 'cf2': dict(max_versions=1, block_cache_enabled=False),
  5. 'cf3': dict(), # use defaults
  6. }
  7. )
  8. table = connection.table('mytable')
上一篇:在树莓派上安装游戏模拟器


下一篇:为Tornado配置Nginx反向代理