Git Product home page Git Product logo

nebula-python's Introduction

NebulaGraph Python Client

pdm-managed pypi-version python-version

Getting Started

Note: Ensure you are using the correct version, refer to the Capability Matrix for how the Python client version corresponds to the NebulaGraph Database version.

Accessing NebulaGraph

Handling Query Results

Jupyter Notebook Integration

Open In Colab

If you are about to access NebulaGraph within Jupyter Notebook, you may want to use the NebulaGraph Jupyter Extension, which provides a more interactive way to access NebulaGraph. See also this on Google Colab: NebulaGraph on Google Colab.

Obtaining nebula3-python

Method 1: Installation via pip

# for v3.x
pip install nebula3-python==$version
# for v2.x
pip install nebula2-python==$version

Method 2: Installation via source

Click to expand
  • Clone from GitHub
git clone https://github.com/vesoft-inc/nebula-python.git
cd nebula-python
  • Install from source

For python version >= 3.7.0

pip install .

For python version >= 3.6.2, < 3.7.0

python3 setup.py install

Quick Example: Connecting to GraphD Using Graph Client

from nebula3.gclient.net import ConnectionPool
from nebula3.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 basketballplayer')

# 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 basketballplayer')
    result = session.execute('SHOW TAGS')
    print(result)

# close the pool
connection_pool.close()

Using the Session Pool: A Guide

The session pool is a collection of sessions that are managed by the pool. It is designed to improve the efficiency of session management and to reduce the overhead of session creation and destruction.

Session Pool comes with the following assumptions:

  1. A space must already exist in the database prior to the initialization of the session pool.
  2. Each session pool is associated with a single user and a single space to ensure consistent access control for the user. For instance, a user may possess different access permissions across various spaces. To execute queries in multiple spaces, consider utilizing several session pools.
  3. Whenever sessionPool.execute() is invoked, the session executes the query within the space specified in the session pool configuration.
  4. It is imperative to avoid executing commands through the session pool that would alter passwords or remove users.

For more details, see SessionPoolExample.py.

Example: Server-Side Evaluated Parameters

To enable parameterization of the query, refer to the following example:

Note: Not all tokens of a query can be parameterized. You can quickly verify it via iPython or Nebula-Console in an interactive way.

params = {
    "p1": 3,
    "p2": True,
    "p3": "Bob",
    "ids": ["player100", "player101"], # second query
}

resp = client.execute_py(
    "RETURN abs($p1)+3 AS col1, (toBoolean($p2) and false) AS col2, toLower($p3)+1 AS col3",
    params,
)
resp = client.execute_py(
    "MATCH (v) WHERE id(v) in $ids RETURN id(v) AS vertex_id",
    params,
)

For further information, consult Params.py.

Example: Extracting Edge and Vertex Lists from Query Results

For graph visualization purposes, the following code snippet demonstrates how to effortlessly extract lists of edges and vertices from any query result by utilizing the ResultSet.dict_for_vis() method.

result = session.execute(
    'GET SUBGRAPH WITH PROP 2 STEPS FROM "player101" YIELD VERTICES AS nodes, EDGES AS relationships;')

data_for_vis = result.dict_for_vis()

Then, we could pass the data_for_vis to a front-end visualization library such as vis.js, d3.js or Apache ECharts. There is an example of Apache ECharts in exapmple/apache_echarts.html.

The dict/JSON structure with dict_for_vis() is as follows:

Click to expand
{
    'nodes': [
        {
            'id': 'player100',
            'labels': ['player'],
            'props': {
                'name': 'Tim Duncan',
                'age': '42',
                'id': 'player100'
            }
        },
        {
            'id': 'player101',
            'labels': ['player'],
            'props': {
                'age': '36',
                'name': 'Tony Parker',
                'id': 'player101'
            }
        }
    ],
    'edges': [
        {
            'src': 'player100',
            'dst': 'player101',
            'name': 'follow',
            'props': {
                'degree': '95'
            }
        }
    ],
    'nodes_dict': {
        'player100': {
            'id': 'player100',
            'labels': ['player'],
            'props': {
                'name': 'Tim Duncan',
                'age': '42',
                'id': 'player100'
            }
        },
        'player101': {
            'id': 'player101',
            'labels': ['player'],
            'props': {
                'age': '36',
                'name': 'Tony Parker',
                'id': 'player101'
            }
        }
    },
    'edges_dict': {
        ('player100', 'player101', 0, 'follow'): {
            'src': 'player100',
            'dst': 'player101',
            'name': 'follow',
            'props': {
                'degree': '95'
            }
        }
    },
    'nodes_count': 2,
    'edges_count': 1
}

Example: Retrieve Primitive Typed Results

The executed result is typed as ResultSet, and you can inspect its structure using dir().

For each data cell in the ResultSet, you can use .cast() to retrieve raw wrapped data (with sugar) such as a Vertex (Node), Edge (Relationship), Path, Value (Int, Float, etc.). Alternatively, you can use .cast_primitive() to obtain values in primitive types like dict, int, or float, depending on your needs.

For more details, refer to FromResp.py.

Additionally, ResultSet.as_primitive() provides a convenient method to convert the result set into a list of dictionaries (similar to JSONL format) containing primitive values for each row.

result = session.execute('<your query>')

result_dict = result.as_primitive()
print(result_dict)

Example: Fetching Query Results into a Pandas DataFrame

For nebula3-python>=3.6.0:

Assuming you have pandas installed, you can use the following code to fetch query results into a pandas DataFrame:

pip3 install pandas
result = session.execute('<your query>')
df = result.as_data_frame()
For `nebula3-python<3.6.0`:
from nebula3.gclient.net import ConnectionPool
from nebula3.Config import Config
import pandas as pd
from typing import Dict
from nebula3.data.ResultSet import ResultSet

def result_to_df(result: ResultSet) -> pd.DataFrame:
    """
    build list for each column, and transform to dataframe
    """
    assert result.is_succeeded()
    columns = result.keys()
    d: Dict[str, list] = {}
    for col_num in range(result.col_size()):
        col_name = columns[col_num]
        col_list = result.column_values(col_name)
        d[col_name] = [x.cast() for x in col_list]
    return pd.DataFrame(d)

# define a config
config = Config()

# 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 2 with session_context, session will be released automatically
with connection_pool.session_context('root', 'nebula') as session:
    session.execute('USE <your graph space>')
    result = session.execute('<your query>')
    df = result_to_df(result)
    print(df)

# close the pool
connection_pool.close()

Quick Example: Using Storage Client to Scan Vertices and Edges

Storage Client enables you to scan vertices and edges from the storage service instead of the graph service w/ nGQL/Cypher. This is useful when you need to scan a large amount of data.

Click to expand

You should make sure the scan client can connect to the address of storage which see from SHOW HOSTS

from nebula3.mclient import MetaCache, HostAddr
from nebula3.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)

See ScanVertexEdgeExample.py for more details.

Compatibility Matrix

Nebula-Python Version Compatible NebulaGraph Versions Notes
3.8.2 3.x Highly recommended. Latest release for NebulaGraph 3.x series.
master master Includes recent changes. Not yet released.
3.0.0 ~ 3.5.1 3.x Compatible with any released version within the NebulaGraph 3.x series.
2.6.0 2.6.0, 2.6.1
2.5.0 2.5.0
2.0.0 2.0.0, 2.0.1
1.0 1.x

Directory Structure Overview

.
└──nebula-python
    │
    ├── nebula3                               // client source code
    │   ├── fbthrift                          // the RPC code generated from thrift protocol
    │   ├── common
    │   ├── data
    │   ├── graph
    │   ├── meta
    │   ├── net                               // the net code for graph client
    │   ├── storage                           // the storage client code
    │   ├── Config.py                         // the pool config
    │   └── Exception.py                      // the exceptions
    │
    ├── examples
    │   ├── FormatResp.py                     // the format response example
    │   ├── SessionPoolExample.py             // the session pool example
    │   ├── GraphClientMultiThreadExample.py  // the multi thread example
    │   ├── GraphClientSimpleExample.py       // the simple example
    │   └── ScanVertexEdgeExample.py          // the scan vertex and edge example(storage client)
    │
    ├── tests                                 // the test code
    │
    ├── setup.py                              // used to install or package
    │
    └── README.md                             // the introduction of nebula3-python

Contribute to Nebula-Python

Click to expand

To contribute, start by forking the repository. Next, clone your forked repository to your local machine. Remember to substitute {username} with your actual GitHub username in the URL below:

git clone https://github.com/{username}/nebula-python.git
cd nebula-python

For package management, we utilize PDM. Please begin by installing it:

pipx install pdm

Visit the PDM documentation for alternative installation methods.

Install the package and all dev dependencies:

pdm install

Make sure the Nebula server in running, then run the tests with pytest:

pdm test

Using the default formatter with black.

Please run pdm fmt to format python code before submitting.

See How to contribute for the general process of contributing to Nebula projects.

nebula-python's People

Contributors

aiee avatar alan890104 avatar amber1990zhang avatar beautyyuyanli avatar chrischen2023 avatar cpwstatic avatar czpmango avatar darionyaphet avatar dutor avatar ghjhhyuyuy avatar greyli avatar gumupaier avatar haoxins avatar harrischu avatar javagithub2022 avatar jievince avatar kikimo avatar knwng avatar laoshubaby avatar laura-ding avatar liuxiaocs7 avatar nicole00 avatar sherif-abdelkarim avatar sophie-xie avatar vector233 avatar wey-gu avatar whitewum avatar yihong0618 avatar yixinglu avatar zhangweidev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nebula-python's Issues

ipython-ngql, a PoC of Jupyter extension to enable nGQL queries like %ngql SHOW SPACES

Dear all,

First, I felt really grateful that you accepted my first PR, thanks so much, it means a lot to me! 😁

When thinking about python ng users, I came to an idea that there could be cases they would like to make queries or tweak data from Jupyter Notebooks, and it turned out there are indeed such things out there for SQL-DB or Cypher.

Thus I spent some time during the weekend creating a PoC on this topic, with which, we could do something like the below image showed to query and manipulate ng's data inside Jupyter notebooks, this enables data scientists to share rerunnable/ readable notebooks with rendered Markdown descriptions, machine learning python codes and results together with nebula graph nGQL querying and results(as human-readable output by default, as image-0), with native python integrations(supports variable in nGQL yields local python variables, as image-1).

image-0, an example of a query in a Jupyter notebook
image-0

image-1, example on local variable rendered in nGQL lines
image-1

The code was put here with more details and it's in a demo shape only (no tests, only tried with a few basic queries). You could try it out(pip install ipython-ngql in your iPython/Jupyter Notes if you promise not to use too fancy queries to break the humble PoC code 😛.

What do you think about this, please? I registered the PyPi name as ipython-ngql while if the plan is going to use it as this separate package, I will hand over the ownership to the community. Or maybe it's possible to consider implementing this in the nebula-python repo itself and not only support %ngql <query> but also %opencypher <query> in the future 😉.

Thanks a lot!
BR//Wey

hello, please publish a new release

hello, friends.

current version (nebula2-python==2.0.0.post1 from https://pypi.org) seems not work with latest nebula2,

node.get_id(), relationship..start_vertex_id() and relationship..end_vertex_id() will throw error.

current master branch is ok.

so will you publish a new release recently?

thanks.

remove meta cache

MetaManager is a cache info for nebula meta, but in client, the schema info will not be read many times, and the cache does not make mush sense.
Besides, if the leader info changed in nebula server, the cache will not know it and will not update, which keeps the old and wrong meta info.

"please update the client"

After updating nebula-graph from 3.0.0 to 3.0.1 we see a strange error message (down below).
Client is nebula3-python installed via pip3 install nebula3-python

File "/home/mastermind/harmony/nebulaapi.py", line 29, in execute
    with connection.session_context(config.nebula['user'], config.nebula['pass']) as session:
File "/usr/local/lib/python3.9/contextlib.py", line 117, in __enter__
    return next(self.gen)
File "/home/user/.local/lib/python3.9/site-packages/nebula3/gclient/net/ConnectionPool.py", line 130, in session_context
    session = self.get_session(*args, **kwargs)
File "/home/user/.local/lib/python3.9/site-packages/nebula3/gclient/net/ConnectionPool.py", line 109, in get_session
    auth_result = connection.authenticate(user_name, password)
File "/home/user/.local/lib/python3.9/site-packages/nebula3/gclient/net/Connection.py", line 112, in authenticate
    raise AuthFailedException(resp.error_msg)
nebula3.Exception.AuthFailedException: b'The version of the client sending request from "::ffff:11.22.33.44":36260 is lower than v2.6.0, please update the client.'

Suggestions for debugging the output

If you are debugging output code, can you remove the test code, such as print() output, or use the logging module to set the output level to debug

Connect to nebula server from another server

I connect from another server to nebula server via this code:

from nebula2.Config import Config
from nebula2.mclient import MetaCache
from nebula2.gclient.net import ConnectionPool
from nebula2.sclient.GraphStorageClient import GraphStorageClient

config = Config()
config.max_connection_pool_size = 10

connection_pool = ConnectionPool()
ok = connection_pool.init([('192.168.10.100', 9669)], config)
session = connection_pool.get_session('admin', 'pass')
meta_cache = MetaCache([('192.168.10.100', 9559)],50000)

## for instance "192.168.10.100"  is ip address of nebula server

return for ok: true
and after that I can execute query like "SHOW SPACES"
but when I use graph_storage_client = GraphStorageClient(meta_cache) it returns this error:

Create storage connection failed: socket error connecting to host 127.0.0.1, port 9779 (('127.0.0.1', 9779)): ConnectionRefusedError(111, 'Connection refused')

what can I do?

[feat] run test ci when upstream repo update

image

Because this CI depends on the upstream repo.
So CI may failed when the upstream repo changed.

we can add some curl command when then upstream update trigger this CI

something like

curl -H "Content-Type:application/json" -X POST -d '{"inputs": {}, "ref":"main"}' https://api.github.com/repos/yihong0618/2021/actions/workflows/${id}/dispatches -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}"

The api workflow doc here

the module cannot analyse return data that contains datetime type

example code in README.md:

session = connection_pool.get_session('root', 'nebula')
result = session.execute('example')

In class Session init,
self._timezone_offset = auth_result.get_timezone_offset()
It may expect an integer value, but actually it's None.
so it calls an error:

File "nebula2/data/DataObject.py", line 885, in __repr__
    return "utc datetime: %d-%02d-%02dT%02d:%02d:%02d.%06d, timezone_offset: %d" % (
TypeError: %d format: a number is required, not NoneType

metad服务地址转成127.0.0.1

graph_storage_client = GraphStorageClient(meta_cache)代码会把我填的服务器地址转成127.0.0.1,导致无法在本地上运行,只能在服务器上运行,这个要怎么解决?

访问不到ScanSpace?

https://github.com/vesoft-inc/nebula-python/blob/master/example/ScanVertexEdgeExample.py

`
from nebula2.Config import Config
from nebula2.gclient.net import ConnectionPool
from nebula2.mclient import MetaCache
from nebula2.sclient.GraphStorageClient import GraphStorageClient
import random
import sys
import time

def prepare_data():
config = Config()
config.max_connection_pool_size = 1
# init connection pool
connection_pool = ConnectionPool()
# the graphd server's address
assert connection_pool.init([('192.168.14.8', 9669)], config)
client = connection_pool.get_session('root', 'root')
client.execute('CREATE SPACE IF NOT EXISTS ScanSpace('
'PARTITION_NUM=10,'
'vid_type=FIXED_STRING(20));'
'USE ScanSpace;'
'CREATE TAG IF NOT EXISTS person(name string, age int);'
'CREATE EDGE IF NOT EXISTS friend(start int, end int);')
time.sleep(5)
result = client.execute('SHOW TAGS')
print(result)

for id in range(20):
    vid = 'person' + str(id)
    cmd = 'INSERT VERTEX person(name, age) ' \
          'VALUES \"{}\":(\"{}\", {})'.format(vid, vid, id)
    client.execute(cmd)
for id in range(20):
    src_id = 'person' + str(id)
    dst_id = 'person' + str(20 - id)
    start = random.randint(2000, 2010)
    end = random.randint(2010, 2020)
    cmd = 'INSERT EDGE friend(start, end) ' \
          'VALUES \"{}\"->\"{}\":({}, {})'.format(src_id, dst_id, start, end)
    client.execute(cmd)
client.release()
connection_pool.close()

def scan_person_vertex(graph_storage_client):
resp = graph_storage_client.scan_vertex(
space_name='ScanSpace',
tag_name='person',
limit=100)
print('======== Scan vertexes in ScanSpace ======')
while resp.has_next():
result = resp.next()
for vertex_data in result:
print(vertex_data)

def scan_person_edge(graph_storage_client):
resp = graph_storage_client.scan_edge(
space_name='ScanSpace',
edge_name='friend',
limit=100)
print('======== Scan edges in ScanSpace ======')
while resp.has_next():
result = resp.next()
for edge_data in result:
print(edge_data)
############################
meta_cache = MetaCache([('192.168.14.8', 9669)],
50000)
graph_storage_client = GraphStorageClient(meta_cache)
prepare_data()
scan_person_vertex(graph_storage_client)
scan_person_edge(graph_storage_client)
`
############################
image

provide paging for GraphStorageClient.scan_edge()

User should be able to perform paging retrieve through GraphStorageClient.scan_edge(), but currently we see only limit parameter, we should add new parameter like offset in this method, the corresponding rpc parameter is ScanEdgeRequest.cursor.

测试example里的例子遇到的问题

image
修改对应的ip和port后,运行一直出现如下找不到对应spacename:
Traceback (most recent call last):
File "F:/dongao_dyy/pycharm_projects/hanlp_extract/connect/ngdb_handle.py", line 126, in
scan_person_vertex(graph_storage_client)
File "F:/dongao_dyy/pycharm_projects/hanlp_extract/connect/ngdb_handle.py", line 51, in scan_person_vertex
limit=100)
File "D:\Anaconda3\envs\hanlp\lib\site-packages\nebula2_python-2.0.0-py3.7.egg\nebula2\sclient\GraphStorageClient.py", line 98, in scan_vertex
part_leaders = self.meta_cache.get_part_leaders(space_name)
File "D:\Anaconda3\envs\hanlp\lib\site-packages\nebula2_python-2.0.0-py3.7.egg\nebula2\mclient_init
.py", line 326, in get_part_leaders
raise SpaceNotFoundException(space_name)
nebula2.Exception.SpaceNotFoundException: ScanSpace
明明已经存在space:ScanSpace为什么总报这个错误,望指教!!!

About code notes

Can scan_vertex() give some notes? I run the example directly and report the following error
image

session pool

A reference to session pool implementation, or provide one.

I did a dirty/ugly implementation in POC of RFC of an upstream project here, we/I may try to do this from nebula-python itself.

pip install nebula2-python failed

pip install --upgrade pip
Collecting pip
Downloading pip-20.3.3-py2.py3-none-any.whl (1.5 MB)
|████████████████████████████████| 1.5 MB 1.8 MB/s
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 20.2.4
Uninstalling pip-20.2.4:
Successfully uninstalled pip-20.2.4
Successfully installed pip-20.3.3
(venv3) sin-l-00040531:nebula-python ghu$ pip install nebula2-python
Collecting nebula2-python
Using cached nebula2-python-2.0.0.post1.tar.gz (208 kB)
ERROR: Command errored out with exit status 1:
command: /Users/ghu/venv3/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/70/l0j2y_9n4r77xk73rcn3cjzh0000gp/T/pip-install-njme8vo5/nebula2-python_ce8687f99fac4defa2066899ce5bd31b/setup.py'"'"'; file='"'"'/private/var/folders/70/l0j2y_9n4r77xk73rcn3cjzh0000gp/T/pip-install-njme8vo5/nebula2-python_ce8687f99fac4defa2066899ce5bd31b/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/70/l0j2y_9n4r77xk73rcn3cjzh0000gp/T/pip-pip-egg-info-ocjnz21x
cwd: /private/var/folders/70/l0j2y_9n4r77xk73rcn3cjzh0000gp/T/pip-install-njme8vo5/nebula2-python_ce8687f99fac4defa2066899ce5bd31b/
Complete output (5 lines):
Traceback (most recent call last):
File "", line 1, in
File "/private/var/folders/70/l0j2y_9n4r77xk73rcn3cjzh0000gp/T/pip-install-njme8vo5/nebula2-python_ce8687f99fac4defa2066899ce5bd31b/setup.py", line 9, in
from setuptools import setup, find_packages, sic
ImportError: cannot import name 'sic' from 'setuptools' (/Users/ghu/venv3/lib/python3.7/site-packages/setuptools/init.py)
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

获取HostAddr时会把每次配置的历史配置都读取下来,导致无法连接storage

image

如上图,我打印出来的HostAddr列表有4个,但是我正确的配置应该只有一个storage地址,应该是我本机的内网地址才对。我把nebula服务进行重装之后,依然还会获取到先前配置的这4个历史addr,希望您能告诉我哪里可以修改获取这个地址的缓存,将不需要的无效地址去除掉,不然无法正常连接服务。

raise RuntimeError( RuntimeError: The services status exception: [services: ('127.0.0.1', 9669), status: BAD]

Nebula services are running
[INFO] nebula-metad: Running as 49784, Listening on 9559 [INFO] nebula-graphd: Running as 49847, Listening on 9669 [INFO] nebula-storaged: Running as 49873, Listening on 9779
However the following code to connect to nebula graph as mentioned on github page
`from nebula3.gclient.net import ConnectionPool
from nebula3.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)`

gives

raise RuntimeError(
RuntimeError: The services status exception: [services: ('127.0.0.1', 9669), status: BAD]

No ID in ResultSet

Hi, congratulations about your amazing database.

I am using Nebula DB v2-nightly, and Client Python V2.0.0-RC1
When I made a query in Web Console: (for example: match(a:Datacenter) return a; ), the response is something like:
{
"code": 0,
"data": {
"headers": [
"a"
],
"tables": [
{
"a": "(-8898061935899072461 :Datacenter{id: "007", name: "DCName", server: "DCServer"})",
"properties": {
"Datacenter": {
"id": "007",
"name": "DCName",
"server": "DCServer"
}
},
"tags": [
"Datacenter"
],
"type": "vertex",
"vid": -8898061935899072461
},
(... all vertex had same struture)

But, when I made the same query in python client, I had the response:

ResultSet(ExecutionResponse(
error_code=0,
latency_in_us=3500,
data=DataSet(
column_names=[b'a'],
rows=[Row(
values=[Value(
vVal=Vertex(
tags=[Tag(
name=b'Datacenter',
props={b'id': Value(
sVal=b'007'),
b'name': Value(
sVal=b'DCName'),
b'server': Value(
sVal=b'DCServer')})]))]),

so... where is the vertex ID ?? (vid) ?
when I try to print this resultset:

+------------------------------------------------------------------+
| a |
+------------------------------------------------------------------+
| {Node}([None]:{{tag_name: b'Datacenter', props: {b'name': Value( |
| sVal=b'DCName'), b'server': Value( |
| sVal=b'DCServer'), b'id': Value( |
| sVal=b'007')}}}) |

Node is indexed by "None"...
if in my query, I specify: match(a:Datacenter) return id(a) as ID, a I will receive the right id in ID Column, but a colum still has "None"

Socket write failed

你好,我们采用的nebula2.6版本 python sdk也是2.6版本,硬件配置4C8G,目前nebula中vector在1000左右,使用python sdk在间隔2-3天就会报socket write failed,需要重启服务连接nebula才能正常使用。

请问这是配置相关的问题?
python连接nebula 没有添加额外的配置参数

nebula2-python中如何使用nebula-python中的获取全部点和边的方法scan_vertex,scan_edge

在nebula-python中,按照如下的方式可以查询nebula中全部的点和边:

meta_client = MetaClient([('192.168.8.16', 45500)])
meta_client.connect()
storage_client = StorageClient(meta_client)
scan_edge_processor = ScanEdgeProcessor(meta_client)

scan_edge_response_iterator = storage_client.scan_edge(space_name, return_cols, all_cols, limit, start_time, end_time)
while scan_edge_response_iterator.has_next():
scan_edge_response = scan_edge_response_iterator.next()
if scan_edge_response is None:
print("Error occurs while scaning edge")
break
result = scan_edge_processor.process(space_name, scan_edge_response)
for edge_name, edge_rows in result.rows.items():
...
...

请问,在nebula2-python中,如何调用类似的scan_edge和scan_vertex

api全变了,找不到了。。。

enable scan_edge to retrive reverse edge

GraphStorageClient.scan_edge() lack option to retrieve reverse edge despite the fact that it's supported by the underlying rpc in ScanEdgeRequest.EdgeProp.EdgeType:

    def scan_edge(self,
                  space_name,
                  edge_name,
                  prop_names=[],
                  limit=DEFAULT_LIMIT,
                  start_time=DEFAULT_START_TIME,
                  end_time=DEFAULT_END_TIME,
                  where=None,
                  only_latest_version=False,
                  enable_read_from_follower=True,
                  partial_success=False):

是否支持异步操作 async/await?

我查看之前某个版本合并了一个pr, 有提到支持async操作,但是在最新的master分支上已经没有

请问是否有支持异步操作的nebula3-python 计划?

Unable to create edge using create edge statement

Here is my code `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()

ok = connection_pool.init([('localhost', 9669)], config)

session = connection_pool.get_session('root', 'nebula')

SHOW SPACES

session.execute("SHOW SPACES")

CREATE SPACE

SPACE_NAME = "nba"
CREATE_SPACE = "CREATE SPACE IF NOT EXISTS nba(partition_num = 5)" # replica_factor not working because single system
session.execute(CREATE_SPACE)

SELECT SPACE

SELECT_SPACE = "USE {}".format(SPACE_NAME)
session.execute(SELECT_SPACE)

DESCRIBE SPACE

session.execute("DESCRIBE SPACE nba")

SHOW TAGS, SPACES

result = session.execute('SHOW TAGS')
print(result)

#CREATE PLAYER TAG
PLAYER_SCHEMA = "name string NOT NULL, age int"
CREATE_PLAYER = "CREATE TAG player({})".format(PLAYER_SCHEMA)
session.execute(CREATE_PLAYER)

CREATE TEAM TAG

TEAM_SCHEMA = "name string"
CREATE_TEAM = "CREATE TAG team({})".format(TEAM_SCHEMA)
session.execute(CREATE_TEAM)

DESCRIBE TAGS GIVES DETAILS OF TAG

result = session.execute('DESCRIBE TAG player')
print(result)

CREATE TAG WITHOUT A PROPERTY

session.execute('CREATE TAG property_free()') # Without using () at the end was not creating this TAG

SHOW TAGS

session.execute("SHOW TAGS")

#DELETE A TAG
DELETE_TAG = "DROP SPACE nba"
session.execute(DELETE_TAG)

CREATE EDGE TYPE

CREATE_EDGE = "CREATE EDGE follow(degree int)"
session.execute(CREATE_EDGE)

session.execute("SHOW EDGES")

CREATE_EDGE = "CREATE EDGE serve(start_year int, end_year int)"
session.execute(CREATE_EDGE)
session.execute("SHOW EDGES")

session.execute("DESCRIBE EDGE serve")`

The output for session.execute("SHOW EDGES") and session.execute("DESCRIBE EDGE serve") is ResultSet(None)

git clone [email protected]:vesoft-inc/nebula-python.git Report an error

$ git clone [email protected]:vesoft-inc/nebula-python.git
Cloning into 'nebula-python'...
The authenticity of host 'github.com (13.229.188.59)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,13.229.188.59' (RSA) to the list of known hosts.
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

But when I use

git clone https://github.com/vesoft-inc/nebula-python.git

is ok

how to get metad servers's address

scan vertex and edge code, there is a line MetaCache([('XXX', 9669),('XXX', 9669),('XXX', 9669)], 50000),how to get the three XXX address?

执行语句出错

INSERT VERTEX disease(text) VALUES "7zThb7ayVbr" : ("## 哪些情况需要及时就医?\n\n如出现以下情况应及时就医:\n\n* 枕颈部疼痛。\n* 感觉功能障碍,如痛觉、温度觉敏感度下降等。\n* 运动功能障碍,如四肢麻木、瘫痪等。\n* 神经损害,如声音嘶哑、吞咽困难等。\n* 出现头晕、恶心、呕吐等颅内压增高表现。\n\n## 建议就诊科室\n\n* 神经外科\n* 肿瘤外科\n\n## 医生如何诊断枕骨大孔脑膜瘤?\n\n医生通常根据患者表现、体格检查、影像学检查后初步疑诊枕骨大孔脑膜瘤,确诊需要病理检查。\n\n具体介绍相关检查:\n\n* 体格检查:医生通过观察患者肢体肌肉萎缩情况、走路姿态等,并进行神经系统专科检查,可以初步判断病灶累及部位。\n* 脊髓造影 CT:注射造影剂(染料,帮助病变显影)后进行 CT 检查,有助于确定病灶发生的部位以及周围受侵情况,可用于本病的诊断及鉴别诊断。\n* 磁共振成像:是诊断本病的最佳方法,对病灶及周围结构的显示优于 CT,可帮助诊断本病。\n* 病理学检查:可用于确诊本病。\n\n## 医生可能询问患者哪些问题?\n\n* 颈部疼痛吗?\n* 出现疼痛多久了?\n* 疼痛的特点是什么?\n* 是否出现四肢麻木?\n* 是否存在走路、站立不稳等症状?\n* 是否存在感觉异常?\n* 有头痛、呕吐吗?\n* 若有以上症状,出现多久了?发作频率如何?有何诱发或者缓解因素?\n\n## 患者可以咨询医生哪些问题?\n\n* 枕骨大孔是哪里?\n* 脑膜瘤是癌症吗?\n* 如何治疗此疾病?\n* 需要做开颅手术吗?\n* 手术后不适症状会消失吗?\n* 手术后此疾病还会复发吗?","True","60%","2-4周","根据不同医院,收费标准不一致,市三甲医院约(10000——50000元)")

同一条语句在 nebula-console 可以执行。

image

ONLY PYTHON-SDK SHOWS ONLY-INCREASING-MEMORY-CURVE WHEN USING "with connection_pool.session_context(username, password) as session" EXECUTE

Hello everyone.

When I use python-sdk for constructiong graph with the official demo says option 2: "with connection_pool.session_context(username, password) as session", It actually seems released dramatically session while sometimes few of session exists as alive.

The most import issuse is the monitor-curve shows my server host get OUT OF MEMORY exception, which leads to the whole service down.

Is there anyone give any hints for this?

  1. each session.execute(SQL) finished, then this session is released, but sometimes didnot
  2. i only use one python-script with eventlet.monkey_patch() for asyo, each batch 3000 points & 9000 edges at most. It seems extremely slow for building a graph with only three kinds of edge with each atmost 1 million;
  3. WHY OOM occurs?

OGM capabilities

Hi, I was referred to Nebula Graph by Hera Han. I'm currently working on a project with a forked Neo4j variant as a backend database. However, I'm considering switching to Nebula due to Neo4j's decision to close source their enterprise product from v3.5, which impacted the forked variant. That being said, my project uses neomodel as an OGM (object graph mapper) to interact with the graph database.

I'm wondering if your package plans to have this capability in the future, as it seems that it currently doesn't have this feature (correct me if I'm wrong). Also, how can I help to advance the development of your package? Do you have a list of TODO's that contributors can find and help with tackling?

[trivial] Introduce contextmanager for ConnectionPool?

Dear,

Do you think it makes sense to enable getting a connection from ConnectionPool with context manager support?

In most cases, the Session.del() already takes care of it for us to release the session when the local Session being recycled, which is great. While still there is a chance in a long routine, where explicitly releasing session could be missing by the end-users. To provide a context manager enabled method to support with statement could be one way forward like:

with connection_pool.session_context('root', 'nebula') as session:
    session.execute('USE nba')
    result = session.execute('SHOW TAGS')
    print(result)

A draft PR for this trivial change is here: #85

Please reject it if it's a silly idea/design :-p. If you consider it's an accepted way to go, I'll be more than happy to continue polishing the PR.
Thanks!

BR, Wey

建议移除logging.basicConfig

项目在这里调用了logging.basicConfig,我认为这种方式是不友好的,会使用户试图定义自己的logger对象时无法直接生效。

建议移除。

ScanVertexEdgeExample.py can't find storage ip

The meta_server is 192.168.61.185:4455,storage_server is 192.168.61.185:6655,and nebula_graph is 192.168.61.185:7755
I've used the correct meta_server's ip:port.
meta_cache = MetaCache([('192.168.61.185', 4455)],50000)
graph_storage_client = GraphStorageClient(meta_cache)
prepare_data()
but the error is
[2021-02-07 13:26:59,966]:Create storage connection failed: socket error connecting to host 127.0.0.1, port 6655 (('127.0.0.1', 6655)): ConnectionRefusedError(61, 'Connection refused') Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/nebula2_python-2.0.0rc1-py3.9.egg/nebula2/fbthrift/transport/TSocket.py", line 279, in open handle.connect(address) ConnectionRefusedError: [Errno 61] Connection refused

pyclient got the loopback address 127.0.0.1:6655, not 192.168.61.185:6655

Failed to install nebula2-python-2.0.0.post1.tar.gz

Using cached nebula2-python-2.0.0.post1.tar.gz (208 kB)
ERROR: Command errored out with exit status 1:
command: /Users/ghu/venv3/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/70/l0j2y_9n4r77xk73rcn3cjzh0000gp/T/pip-install-datfggyz/nebula2-python_4a45945b3bf14ee6a9e458674044738a/setup.py'"'"'; file='"'"'/private/var/folders/70/l0j2y_9n4r77xk73rcn3cjzh0000gp/T/pip-install-datfggyz/nebula2-python_4a45945b3bf14ee6a9e458674044738a/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/70/l0j2y_9n4r77xk73rcn3cjzh0000gp/T/pip-pip-egg-info-gv9uxp3g
cwd: /private/var/folders/70/l0j2y_9n4r77xk73rcn3cjzh0000gp/T/pip-install-datfggyz/nebula2-python_4a45945b3bf14ee6a9e458674044738a/
Complete output (5 lines):
Traceback (most recent call last):
File "", line 1, in
File "/private/var/folders/70/l0j2y_9n4r77xk73rcn3cjzh0000gp/T/pip-install-datfggyz/nebula2-python_4a45945b3bf14ee6a9e458674044738a/setup.py", line 9, in
from setuptools import setup, find_packages, sic
ImportError: cannot import name 'sic' from 'setuptools' (/Users/ghu/venv3/lib/python3.7/site-packages/setuptools/init.py)
----------------------------------------

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.