nebula3.gclient.net package#

Submodules#

nebula3.gclient.net.AuthResult module#

class nebula3.gclient.net.AuthResult.AuthResult(session_id, timezone_offset, timezone_name)#

Bases: object

get_session_id()#
get_timezone_name()#
get_timezone_offset()#

nebula3.gclient.net.Connection module#

class nebula3.gclient.net.Connection.Connection#

Bases: object

authenticate(user_name, password)#

authenticate to graphd

Parameters:
  • user_name – the user name

  • password – the password

Returns:

close()#

close the connection

Returns:

void

execute(session_id, stmt)#

execute interface with session_id and ngql

Parameters:
  • session_id – the session id get from result of authenticate interface

  • stmt – the ngql

Returns:

ExecutionResponse

execute_json(session_id, stmt)#

execute_json interface with session_id and ngql :param session_id: the session id get from result of authenticate interface :param stmt: the ngql :return: string json representing the execution result

execute_json_with_parameter(session_id, stmt, params)#

execute_json interface with session_id and ngql with parameter :param session_id: the session id get from result of authenticate interface :param stmt: the ngql :param params: parameter map :return: string json representing the execution result

execute_parameter(session_id, stmt, params)#

execute interface with session_id and ngql :param session_id: the session id get from result of authenticate interface :param stmt: the ngql :param params: parameter map :return: ExecutionResponse

get_address()#

get the address of the connected service

Returns:

(ip, port)

idle_time()#

get idletime of connection

Returns:

idletime

is_used = False#
open(ip, port, timeout)#

open the connection

Parameters:
  • ip – the server ip

  • port – the server port

  • timeout – the timeout for connect and execute

Returns:

void

open_SSL(ip, port, timeout, ssl_config=None)#

open the SSL connection

Parameters:
  • ip – the server ip

  • port – the server port

  • timeout – the timeout for connect and execute

Ssl_config:

configs for SSL

Returns:

void

ping()#

check the connection if ok :return: True or False

reset()#

reset the idletime

Returns:

void

signout(session_id)#

tells the graphd can release the session info

:param session_id:the session id :return: void

nebula3.gclient.net.ConnectionPool module#

class nebula3.gclient.net.ConnectionPool.ConnectionPool#

Bases: object

S_BAD = 1#
S_OK = 0#
close()#

close all connections in pool

Returns:

void

connects()#

get the number of existing connections

Returns:

the number of connections

get_connection()#

get available connection

Returns:

Connection

get_ok_servers_num()#

get the number of the ok servers

Returns:

int

get_session(user_name, password, retry_connect=True)#

get session

Parameters:
  • user_name – the user name to authenticate graphd

  • password – the password to authenticate graphd

  • retry_connect

Returns:

Session

in_used_connects()#

get the number of the used connections

Returns:

int

init(addresses, configs, ssl_conf=None)#

init the connection pool

Parameters:
  • addresses – the graphd servers’ addresses

  • configs – the config of the pool

  • ssl_conf – the config of SSL socket

Returns:

if all addresses are ok, return True else return False.

ping(address)#

check the server is ok

Parameters:

address – the server address want to connect

Returns:

True or False

session_context(*args, **kwargs)#

session_context is to be used with a contextlib.contextmanager. It returns a connection session from the pool, with same params as the method get_session().

When session_context is exited, the connection will be released.

Parameters:
  • user_name – the user name to authenticate graphd

  • password – the password to authenticate graphd

  • retry_connect – if auto retry connect

Returns:

contextlib._GeneratorContextManager

update_servers_status()#

update the servers’ status

nebula3.gclient.net.Session module#

class nebula3.gclient.net.Session.Session(connection, auth_result: AuthResult, pool, retry_connect=True)#

Bases: object

execute(stmt)#

execute statement

Parameters:

stmt – the ngql

Returns:

ResultSet

execute_json(stmt)#
execute statement and return the result as a JSON string

Date and Datetime will be returned in UTC JSON struct: {

“results”: [ {

“columns”: [], “data”: [ {

“row”: [ “row-data” ], “meta”: [ “metadata” ]

} ], “latencyInUs”: 0, “spaceName”: “”, “planDesc “: { “planNodeDescs”: [

{ “name”: “”, “id”: 0, “outputVar”: “”, “description”: {

“key”: “”

}, “profiles”: [

{ “rows”: 1, “execDurationInUs”: 0, “totalDurationInUs”: 0, “otherStats”: {} }

], “branchInfo”: {

“isDoBranch”: false, “conditionNodeId”: -1

}, “dependencies”: [] }

], “nodeIndexMap”: {}, “format”: “”, “optimize_time_in_us”: 0 }, “comment “: “”

} ], “errors”: [ {

“code”: 0, “message”: “”

}

Parameters:

stmt – the ngql

Returns:

JSON string

execute_json_with_parameter(stmt, params)#
execute statement and return the result as a JSON string

Date and Datetime will be returned in UTC JSON struct: {

“results”: [ {

“columns”: [], “data”: [ {

“row”: [ “row-data” ], “meta”: [ “metadata” ]

} ], “latencyInUs”: 0, “spaceName”: “”, “planDesc “: { “planNodeDescs”: [

{ “name”: “”, “id”: 0, “outputVar”: “”, “description”: {

“key”: “”

}, “profiles”: [

{ “rows”: 1, “execDurationInUs”: 0, “totalDurationInUs”: 0, “otherStats”: {} }

], “branchInfo”: {

“isDoBranch”: false, “conditionNodeId”: -1

}, “dependencies”: [] }

], “nodeIndexMap”: {}, “format”: “”, “optimize_time_in_us”: 0 }, “comment “: “”

} ], “errors”: [ {

“code”: 0, “message”: “”

}

Parameters:
  • stmt – the ngql

  • params – parameter map

Returns:

JSON string

execute_parameter(stmt, params)#

execute statement :param stmt: the ngql :param params: parameter map :return: ResultSet

ping()#

ping at connection level check the connection is valid

Returns:

True or False

ping_session()#

ping at session level, check whether the session is usable

release()#

release the connection to pool, and the session couldn’t been use again

Returns:

nebula3.gclient.net.SessionPool module#

class nebula3.gclient.net.SessionPool.SessionPool(username, password, space_name, addresses)#

Bases: object

S_BAD = 1#
S_OK = 0#
close()#

log out all sessions and close all connections

Returns:

void

execute(stmt)#

execute the given query Notice there are some limitations: 1. The query should not be a plain space switch statement, e.g. “USE test_space”, but queries like “use space xxx; match (v) return v” are accepted. 2. If the query contains statements like “USE <space name>”, the space will be set to the one in the pool config after the execution of the query. 3. The query should not change the user password nor drop a user.

Parameters:

stmt – the query string

Returns:

ResultSet

execute_json(stmt)#
execute statement and return the result as a JSON string

Date and Datetime will be returned in UTC JSON struct: {

“results”: [ {

“columns”: [], “data”: [ {

“row”: [ “row-data” ], “meta”: [ “metadata” ]

} ], “latencyInUs”: 0, “spaceName”: “”, “planDesc “: { “planNodeDescs”: [

{ “name”: “”, “id”: 0, “outputVar”: “”, “description”: {

“key”: “”

}, “profiles”: [

{ “rows”: 1, “execDurationInUs”: 0, “totalDurationInUs”: 0, “otherStats”: {} }

], “branchInfo”: {

“isDoBranch”: false, “conditionNodeId”: -1

}, “dependencies”: [] }

], “nodeIndexMap”: {}, “format”: “”, “optimize_time_in_us”: 0 }, “comment “: “”

} ], “errors”: [ {

“code”: 0, “message”: “”

}

Parameters:

stmt – the ngql

Returns:

JSON string

execute_json_with_parameter(stmt, params)#
execute_parameter(stmt, params)#

execute statement

Parameters:
  • stmt – the query string

  • params – parameter map

Returns:

ResultSet

get_ok_servers_num()#

get the number of the ok servers

Returns:

int

init(configs)#

init the session pool

Parameters:
  • username – the username of the session

  • password – the password of the session

  • space_name – the space name of the session

  • addresses – the addresses of the servers

  • configs – the config of the pool

Returns:

if all addresses are valid, return True else return False.

ping(address)#

check the server is ok

Parameters:

address – the server address want to connect

Returns:

True or False

ping_sessions()#

ping all sessions in the pool

update_servers_status()#

update the servers’ status

Module contents#