# hbase_client **Repository Path**: morre/hbase_client ## Basic Information - **Project Name**: hbase_client - **Description**: 纯Python实现的hbase客户端,已在python 3.9 和 hbase 2.4.5下通过测试。 - **Primary Language**: Python - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-12-30 - **Last Updated**: 2025-02-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: hbase ## README # hbase_client ## 介绍 hbase_client是纯Python实现的hbase客户端,已在python 3.9 和 hbase 2.4.5下通过测试。 ## 软件架构 软件架构说明 ## 安装教程 ### 包依赖 * setuptools>=65.6.3 * intervaltree>=3.0.2 * kazoo>=1.12.0 * protobuf>=3.9.2 * gevent==1.4.0 1. 先安装好protoc,以conda环境为例: ``` shell conda install protobuf git pip -y ``` 如果自行安装protoc,请用环境变量指定: ``` shell export PROTOC="/usr/local/bin/protoc" ``` 2. 从git repo拉取代码并安装 ``` shell pip install git+https://gitee.com/morre/hbase_client.git ``` ## 使用说明 1. hbase客户端对象初始化 ``` python from hbase_client import HbaseClient zkquorum = "hbase_site.conf中的hbase.zookeeper.quorum" zk_root_path = "hbase_site.conf中的zookeeper.znode.parent" client_obj = HbaseClient(zkquorum = zkquorum, zk_root_path = zk_root_path, init_socket_pool_size = 1, establish_connection_timeout = 60, missing_znode_retries = 3, rpc_socket_timeout = 30) ``` 2. 启动和zookeeper服务的链接 ``` python client_obj.open() ``` 3. 发起put请求 ``` python print(client_obj.put(b"test_table", b"test1", {b"data": {b"value": b"test"}})) ``` 4. 发起get请求,查看put结果 ``` python print(client_obj.get(b"test_table", b"test1")) ``` 5. 发起delete请求 ``` python print(client_obj.delete(b"test_table", b"test1", {b"data": {b"value": "test"}})) ``` 6. 发起get请求,查看delete结果 ``` python print(client_obj.get(b"test_table", b"test1")) ``` 7. 循环处理scan请求 ``` python for cell in client_obj.scan(table=b"test_table", batch_size=10, reverse=False): print(cell) ``` ## TIPS 1. 在调用client发起请求前需要先open,后续考虑auto_connect。 2. 需要注意HbaseClient构造函数、put、get、delete等函数均有auto_flush参数,如果为True则使用同步方式提交操作,否则会走gevent的异步提交。 3. 在使用put测试单条数据写入时,注意打开auto_flush,在hadoop上建议关闭auto_flush。 4. 在hadoop上调用hbase_client执行批量操作的时候,需要事先本地缓存好hbase meta表的region信息,参考dump_meta_to_sqlite、load_meta_from_sqlite、load_meta函数,详见[demo](https://gitee.com/morre/hbase_client/blob/master/demo/run.sh) 。 5. 格式错误定位:所有请求都在[request_util.py](https://gitee.com/morre/hbase_client/blob/master/hbase_client/request_util.py)中封装,可对比查看格式问题。 6. 其他exception定位:java server端的异常,都是已知的异常。 ## TODO * 加入单测代码 * 加入获取空值判断表是否存在的异常 * 加入pyspark示例代码 ## 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request ## 特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)