Python客户端用于Nebula Graph V2.6
项目描述
nebula-python
此目录包含Nebula Graph的Python API。它用于连接Nebula Graph 2.0。
开始之前
在开始之前,请阅读本节以选择适合您的分支。在v1.0分支中,API仅适用于Nebula Graph 1.0。在master分支中,API仅适用于Nebula Graph 2.0。
目录结构
|--nebula-python
|
|-- nebula2 // client code
| |-- fbthrift // the fbthrift lib code
| |-- common
| |-- data
| |-- graph
| |-- meta
| |-- net // the net code for graph client
| |-- storage
| |-- Config.py // the pool config
| |__ Exception.py // the define exception
|
|-- examples
| |-- GraphClientMultiThreadExample.py // the multi thread example
| |-- GraphClientSimpleExample.py // the simple example
| |__ ScanVertexEdgeExample.py
|
|-- tests // the test code
|
|-- setup.py // used to install or package
|
|__ README.md // the introduction of nebula2-python
如何获取nebula2-python
选项一:从GitHub克隆
- 从GitHub克隆
git clone https://github.com/vesoft-inc/nebula-python.git
cd nebula-python
- 安装
sudo python3 setup.py install
当您的环境无法访问pypi
时,您需要手动安装以下包。
pip install -r requirements.txt
开发版本
pip install -r requirements-dev.txt
选项二:使用pip
pip install nebula2-python==$version
快速示例:使用graph-client连接graphd
from nebula2.gclient.net import ConnectionPool
from nebula2.Config import Config
# define a config
config = Config()
config.max_connection_pool_size = 10
# init connection pool
connection_pool = ConnectionPool()
# if the given servers are ok, return true, else return false
ok = connection_pool.init([('127.0.0.1', 9669)], config)
# option 1 control the connection release yourself
# get session from the pool
session = connection_pool.get_session('root', 'nebula')
# select space
session.execute('USE nba')
# show tags
result = session.execute('SHOW TAGS')
print(result)
# release session
session.release()
# option 2 with session_context, session will be released automatically
with connection_pool.session_context('root', 'nebula') as session:
session.execute('USE nba')
result = session.execute('SHOW TAGS')
print(result)
# close the pool
connection_pool.close()
快速示例:使用storage-client扫描顶点和边
您应该确保扫描客户端可以连接到从SHOW HOSTS
看到的存储地址
from nebula2.mclient import MetaCache, HostAddr
from nebula2.sclient.GraphStorageClient import GraphStorageClient
# the metad servers's address
meta_cache = MetaCache([('172.28.1.1', 9559),
('172.28.1.2', 9559),
('172.28.1.3', 9559)],
50000)
# option 1 metad usually discover the storage address automatically
graph_storage_client = GraphStorageClient(meta_cache)
# option 2 manually specify the storage address
storage_addrs = [HostAddr(host='172.28.1.4', port=9779),
HostAddr(host='172.28.1.5', port=9779),
HostAddr(host='172.28.1.6', port=9779)]
graph_storage_client = GraphStorageClient(meta_cache, storage_addrs)
resp = graph_storage_client.scan_vertex(
space_name='ScanSpace',
tag_name='person')
while resp.has_next():
result = resp.next()
for vertex_data in result:
print(vertex_data)
resp = graph_storage_client.scan_edge(
space_name='ScanSpace',
edge_name='friend')
while resp.has_next():
result = resp.next()
for edge_data in result:
print(edge_data)
如何选择nebula-python
Nebula2-Python版本 | NebulaGraph版本 |
---|---|
2.0.0b1 | 2.0.0beta |
2.0.0rc1 | 2.0.0-rc1 |
2.0.0 | 2.0.0/2.0.1 |
2.5.0 | 2.5.0 |
2.6.0 | 2.6.0 |
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源代码分发
nebula2-python-2.6.1.tar.gz (254.3 kB 查看哈希值)
构建分发
nebula2_python-2.6.1-py3-none-any.whl (301.8 kB 查看哈希值)
关闭
nebula2-python-2.6.1.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | b77219f0345ea8b9f06dc7fd0eb3ecd56a06a60aa7032ee492e30e3b63162f1f |
|
MD5 | 8730adc0abe834ba51af3b8ae805fe74 |
|
BLAKE2b-256 | c160091a0b52043f8ff6f263283f976d102f642cbd4de66fa94587051e8a8bcb |
关闭
nebula2_python-2.6.1-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 42ffe7791143d65a23480a8a9ee6d99e9fc11e5d12e2af61793f5d08b2534816 |
|
MD5 | 30d8a9f3721fd738031c59d94cf4a9b0 |
|
BLAKE2b-256 | 49a875bf56857e3d42f33d569b449be3435f82b783a4d57fcaab34349cc029bd |