Python编程:happybase读写HBase数据库
2023-09-14 09:07:15 时间
happybase文档:
https://happybase.readthedocs.io/en/latest/
安装
pip install happybase
表操作
import happybase
# 连接数据库
connection = happybase.Connection(host='hostname', port=9090)
# 查询所有表
table_name_list = connection.tables()
# 建表
families = {
'user_info': dict(),
'history': dict()
}
connection.create_table('table_name', families)
# 删除表
connection.delete_table(name, disable=False)
数据操作
table = connection.table('table-name')
# 获取列族信息
info_dict = table.families()
# 添加数据
data = {
'family:key1': 'value1',
'family:key2': 'value2'
}
table.put(b'row-key', data)
# 查询数据
row = table.row(b'row-key')
# 删除数据
row = table.delete(b'row-key')
批量数据操作
# 批量添加
bat = table.batch()
bat.put('row-key1', {'family:key1': 'value1', 'family:key2': 'value2'})
bat.put('row-key2', {'family:key1': 'value1', 'family:key2': 'value2'})
bat.send()
# 批量查询
rows_list = table.rows(['row-key1', 'row-key2']) # 返回list
rows_dict = dict(table.rows(['row-key1', 'row-key2']))# 返回dict
相关文章
- Python怎么输入小数和整数_python输入非负整数
- Python入门系列(十一)一篇搞定python操作MySQL数据库
- gyp ERR! stack Error: Can't find Python executable 'python'
- python attrs_Python attrs作用是什么?
- python lambda表达式举例_Python中lambda表达式[通俗易懂]
- python-Python与SQLite数据库-SQLite数据库的基本知识(一)
- python-Python与SQLite数据库-处理SQLite查询结果(一)
- python-Python与PostgreSQL数据库-PostgreSQL数据库的基本知识(二)
- Python去除字符串中空格(删除指定字符)的3种方法
- 掌握Python访问MySQL的新技能(python访问mysql)
- Python简易操作MySQL数据库指南(python操作mysql数据库)
- Redis与Hbase:探索高效缓存和分布式数据库的最佳实践(redis与hbase)
- 比较:MYSQL与HBASE 数据库管理系统的异同(mysql与hbase)
- Python在连接MSSQL数据库中的应用(python连mssql)
- Python脚本实现Linux命令快捷控制(python执行linux命令)