Skip to main content

Python client for Nebula Graph V3.0

Project description

nebula-python

This repository holds the official Python API for Nebula Graph.

Before you start

Before you start, please read this section to choose the right branch for you. The compatibility between the API and Nebula Graph service can be found in How to choose nebula-python. The current master branch is compatible with Nebula Graph 3.0.

The directory structure

|--nebula-python
    |
    |-- nebula3                               // 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 nebula3-python

How to get nebula3-python

Option one: install with pip

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

Option two: install from the source code

  • Clone from GitHub
git clone https://github.com/vesoft-inc/nebula-python.git
cd nebula-python
  • Install
pip install .

Quick example to use graph-client to connect graphd

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 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()

Quick example to use storage-client to scan vertex and edge

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)

How to choose nebula-python

Nebula-Python Version NebulaGraph Version
1.0 1.x
2.0.0 2.0.0/2.0.1
2.5.0 2.5.0
2.6.0 2.6.0/2.6.1
3.0.0 3.0.0
master master

How to contribute to nebula-python

Fork this repo, then clone it locally (be sure to replace the {username} in the repo URL below with your GitHub username):

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

Install the package in the editable mode, then install all the dev dependencies:

pip install -e .
pip install -r requirements/dev.txt

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

pytest

Using the default formatter with black.

Please run make fmt to format python code before submitting.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nebula3-python-3.0.0.tar.gz (257.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nebula3_python-3.0.0-py3-none-any.whl (303.4 kB view details)

Uploaded Python 3

File details

Details for the file nebula3-python-3.0.0.tar.gz.

File metadata

  • Download URL: nebula3-python-3.0.0.tar.gz
  • Upload date:
  • Size: 257.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for nebula3-python-3.0.0.tar.gz
Algorithm Hash digest
SHA256 376476de7cc3bf7ec6c920f72b5b5b1321a36d9990855c9288475fa31e755a21
MD5 9a83289b10ba51ea06c567abbc901600
BLAKE2b-256 3a783fa7a90a1e7ad1b2d35853d06d91f854e6f2ce286c33f17013b6c6c12902

See more details on using hashes here.

File details

Details for the file nebula3_python-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: nebula3_python-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 303.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for nebula3_python-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b94f977270f0a094abcd15de7acbca09dcb98166be1a90b6f30b4031954f114
MD5 22f9efe178b7084954c6026becb63704
BLAKE2b-256 0d1f9ccbbb890b728f4be9c73c31a47162d29adcf3ccef4c89c31b4937528c61

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page