xgt.Service

class xgt.Service(host='127.0.0.1', port=4367, local=False, debug=False, key_id='', secret_key='')

Connection to the server with functionality to create, change, and remove graph structures and run jobs.

Parameters:
host : str

IP address of the computer where the server is running.

port : int

Port where the server is listening on.

debug : boolean

Run the server in debug mode.

key_id : str

Amazon Access Key ID.

secret_key : str

AWS Secret Access Key corresponding to the AWS Access Key ID.

Methods

about() Obtains some statistics from the server.
cancel_job(jobid) Cancel the execution of a job in the server.
create(obj) Create a new graph or a table in the server.
drop_graph(name) Drop a graph using its name.
drop_table(name) Drop a table using its name.
explain(query) This function is unsupported.
format_explain(query_explanation) This function is unsupported.
get_graph(name) Get a proxy object that allows interaction with the graph.
get_graph_definition(name) Get a textual representation of the graph.
get_graphs() Get a list of graph names present in the server.
get_job(jobid) Get a Job object that represents the state of a job in the server at the point in time of the invocation of this function.
get_job_status(jobid) Get the status of a job.
get_jobs() Get a list of job IDs initiated from the client interface.
get_table(name) Get a proxy object that allows interaction with the table.
get_tables() Get a list of table names present in the server.
run_job(queries[, optlevel, timeout]) Run one a or more TQL queries as a single job.
schedule_job(queries[, optlevel]) Schedule one a or more TQL queries as a single job.
set_optimization_level(optlevel) Set the optimization level for TQL queries.
version() Obtains the current product version from the server.
wait_for_jobs(jobs[, timeout]) Wait for one a or more jobs.
stat_report  
stat_reset  
__init__(host='127.0.0.1', port=4367, local=False, debug=False, key_id='', secret_key='')

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__([host, port, local, debug, key_id, …]) Initialize self.
about() Obtains some statistics from the server.
cancel_job(jobid) Cancel the execution of a job in the server.
create(obj) Create a new graph or a table in the server.
drop_graph(name) Drop a graph using its name.
drop_table(name) Drop a table using its name.
explain(query) This function is unsupported.
format_explain(query_explanation) This function is unsupported.
get_graph(name) Get a proxy object that allows interaction with the graph.
get_graph_definition(name) Get a textual representation of the graph.
get_graphs() Get a list of graph names present in the server.
get_job(jobid) Get a Job object that represents the state of a job in the server at the point in time of the invocation of this function.
get_job_status(jobid) Get the status of a job.
get_jobs() Get a list of job IDs initiated from the client interface.
get_table(name) Get a proxy object that allows interaction with the table.
get_tables() Get a list of table names present in the server.
run_job(queries[, optlevel, timeout]) Run one a or more TQL queries as a single job.
schedule_job(queries[, optlevel]) Schedule one a or more TQL queries as a single job.
set_optimization_level(optlevel) Set the optimization level for TQL queries.
stat_report()
stat_reset()
version() Obtains the current product version from the server.
wait_for_jobs(jobs[, timeout]) Wait for one a or more jobs.

Attributes

REST_VERSION
about()

Obtains some statistics from the server.

Returns:
dict

High level statistics relevant to xgtd.

Examples

>>> conn = xgt.connect()
>>> print(conn.about())
{'version': '0.15.0',
 'platform': 'singlenode',
 'localities': 1,
 'workerthreads': 4,
 'currentmemory': '25.45MB',
 'peakmemory': '25.45MB',
 'totalmemory': '11.82GB'}
cancel_job(jobid)

Cancel the execution of a job in the server.

A job can be canceled only if it is running and will have a status of canceled after its cancellation. A job that already had a status of completed or failed before invoking this function will keep that status after invoking this function.

Parameters:
jobid : int

Job id obtained using the xgt.Service.get_jobs function.

Returns:
Job

Information for the canceled job.

Examples

>>> conn = xgt.connect()
>>> ... create graph(s) and run queries ...
>>> print(conn.get_jobs())
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
>>> print(conn.cancel_job(18))
id:18, status:completed
create(obj)

Create a new graph or a table in the server.

Parameters:
obj : Graph, Table

Instance of Graph or Table with the new graph or table definition.

drop_graph(name)

Drop a graph using its name.

Parameters:
name : str

Graph name.

drop_table(name)

Drop a table using its name.

Parameters:
name : str

Table name.

explain(query)

This function is unsupported.

format_explain(query_explanation)

This function is unsupported.

get_graph(name)

Get a proxy object that allows interaction with the graph.

Parameters:
name : str

Graph name.

Returns:
GraphProxy

Proxy to the graph.

Examples

>>> conn = xgt.connect()
>>> ... create graph(s) ...
>>> g = conn.get_graph('Company')
>>> print(str(g))
{
    'vertices': [{
        'name': 'Employee',
        'key': ['PersonID'],
        'schema': [
            ['PersonID', 'int'],
            ['Name', 'text'],
            ['PostalCode', 'int']]
    }],
    'name':
    'Company',
    'edges': [{
        'source': 'Employee',
        'target': 'Employee',
        'name': 'ReportsTo',
        'schema': [
            ['EmpID', 'int'],
            ['BossID', 'int'],
            ['StartDate', 'date'],
            ['EndDate', 'date']]
    }]
}
get_graph_definition(name)

Get a textual representation of the graph.

Parameters:
name : str

Graph name.

get_graphs()

Get a list of graph names present in the server.

Returns:
list

Names of graphs present in the server.

Examples

>>> conn = xgt.connect()
>>> ... create graph(s) ...
>>> print(conn.get_graphs())
['Company']
get_job(jobid)

Get a Job object that represents the state of a job in the server at the point in time of the invocation of this function.

Parameters:
jobid : int

Job id obtained using the xgt.Service.get_jobs function.

Returns:
Job

State of a job in the server.

Examples

>>> conn = xgt.connect()
>>> ... create graph(s) and run queries ...
>>> print(conn.get_jobs())
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
>>> j = conn.get_job(18)
>>> print(j)
id:18, status:completed
get_job_status(jobid)

Get the status of a job.

Parameters:
jobid : int

Job id obtained using the xgt.Service.get_jobs function.

Returns:
str

Status of the job.

The possible values are:

scheduled The state after the job has been created, but before it has started running
running The job is being executed.
completed The job finished successfully.
canceled The job was canceled.
failed The job failed. When the job fails the error and trace properties are populated.

Examples

>>> conn = xgt.connect()
>>> ... create graph(s) and run queries ...
>>> print(conn.get_jobs())
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
>>> print(conn.get_job_status(18))
completed
get_jobs()

Get a list of job IDs initiated from the client interface.

Returns:
list

A list of integer job IDs.

Examples

>>> conn = xgt.connect()
>>> ... create graph(s) and run queries ...
>>> print(conn.get_jobs())
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
get_table(name)

Get a proxy object that allows interaction with the table.

Parameters:
name : str

Table name.

Returns:
TableProxy

Proxy to the table.

Examples

>>> conn = xgt.connect()
>>> ... create graph and run queries ...
>>> t = conn.get_table('Employee_table')
>>> print(str(t))
{
    'name': 'Employee_table',
    'schema': [
        ['PersonID', 'int'],
        ['Name', 'text'],
        ['PostalCode', 'int']]
}
get_tables()

Get a list of table names present in the server.

Returns:
list

Table names present in the server.

Examples

>>> conn = xgt.connect()
>>> ... create graph and run queries ...
>>> print(conn.get_tables())
['Employee_table', 'ReportsTo_table', 'Result1']
run_job(queries, optlevel=None, timeout=None)

Run one a or more TQL queries as a single job. This function blocks until the job stops running.

If a list of queries is provided each query will be executed one at a time.

Parameters:
queries : str, list

One TQL query string or a list of TQL query strings.

optlevel : int
The optimization level values are:
  • 0: No optimization.
  • 1: General optimization.
  • 2: WHERE-clause optimization.

Optional. Default=None, which implies a value of ‘2’.

timeout : int

Maximum number of seconds that the query should take before being automatically canceled. Optional. Default=None where an infinite value is assumed.

Returns:
list

List of jobs with completed queries.

Raises:
xgt_exception

If any of the query(ies) is not a string (str) or the query text is larger than 209,000 characters. If one or more query jobs failed.

Examples

>>> conn = xgt.connect()
>>> ... create graph(s) ...
>>> job = conn.run_job('MATCH (a:Employee) RETURN a.PersonID INTO Result1')
>>> print(job[0])
id:20, status:completed
>>> conn.run_job('MATCH (a) RETURN a.id INTO Result1')
...
xgt.common.xgt_exception: Failed jobs:
id: 22
error:
VertexTypeManager: No object registered with this ObjectID 18446744073709551615
schedule_job(queries, optlevel=None)

Schedule one a or more TQL queries as a single job. This function returns immediately after scheduling the job.

If a list of queries is provided each query will be executed one at a time.

Parameters:
queries : str, list

One TQL query string or a list of TQL query strings.

optlevel : int
The optimization level values are:
  • 0: No optimization.
  • 1: General optimization.
  • 2: WHERE-clause optimization.

Optional. Default=None, which implies a value of ‘2’.

Returns:
Job

A Job scheduled to run as soon as possible.

Raises:
xgt_exception

If any of the query(ies) is not a string (str) or the query text is larger than 209,000 characters.

Examples

>>> conn = xgt.connect()
>>> ... create graph(s) ...
>>> queries = ['MATCH (a:Employee) RETURN a.PersonID INTO Result1',
               'MATCH (b:Employee) RETURN b.PersonID INTO Result2']
>>> job = conn.schedule_job(queries)
>>> print(job)
id:25, status:scheduled
set_optimization_level(optlevel)

Set the optimization level for TQL queries.

Parameters:
optlevel : int
The optimization level values are:
  • 0: No optimization.
  • 1: General optimization.
  • 2: WHERE-clause optimization.

Optional. Default=None, which implies a value of ‘2’.

version()

Obtains the current product version from the server.

Returns:
str

Version number.

wait_for_jobs(jobs, timeout=None)

Wait for one a or more jobs. This function blocks until all job stop running.

Parameters:
jobs : Job, list

One Job instance or a list of jobs.

timeout : int

Maximum number of seconds that the jobs should take before being automatically canceled. Optional. Default=None (no timeout).

Returns:
list

List of jobs with completed queries.

Raises:
xgt_exception

If any of the query(ies) is not a string (str) or the query text is larger than 209,000 characters. If one or more query jobs failed.

Examples

>>> conn = xgt.connect()
>>> ... create graph(s) ...
>>> qr1 = 'MATCH (a:Employee) RETURN a.PersonID INTO Result1'
>>> jb1 = conn.schedule_job(qr1)
>>> qr2 = 'MATCH (b:Employee) RETURN b.PersonID INTO Result2'
>>> jb2 = conn.schedule_job(qr2)
>>> jobs = conn.wait_for_jobs([jb1, jb2])
>>> print(jobs[0])
id:31, status:completed
>>> print(jobs[1])
id:32, status:completed