The Python interface to the Trovares xGT graph analytics engine.

Main Features

Data loading

xGT is a strongly-typed graph system. Loading data is a two-step process:

  1. Describe the structure and data types of your graph.

    Define the vertex and edge type structure with Connection.create_vertex_frame() and Connection.create_edge_frame(). Once the type structure is set, VertexFrame and EdgeFrame objects provide access to the server-side structures.

  2. Load your edge and vertex data.

    The VertexFrame and EdgeFrame objcts provide high-performance, parallel load() methods to ingest data as well as a direct insert() method to add small amounts of data piecewise.

Query processing

Queries are expressed as strings written in TQL.

>>> query = '''
        MATCH  (emp:Employee)-[edge1:ReportsTo]->(boss:Employee)
        RETURN emp.PersonID AS EmployeeID,
               boss.PersonID AS BossID
        INTO   ResultTable
        '''

A query runs in the context of a Job, which can be run, scheduled and canceled. The run_job() method runs the query and blocks until it finishes successfully, terminates by an error, or it’s canceled.

Example

The following Python script shows some of the functions that can be used to create a graph, load data into it, run a query and access the results, and finally remove that graph from the system.

import xgt

#-- Connect to xgtd --
conn = xgt.Connection()

#-- Define and create the graph --
emp = conn.create_vertex_frame(
          name = 'Employee',
          schema = [['PersonID', xgt.INT],
                    ['Name', xgt.TEXT],
                    ['PostalCode', xgt.INT]],
          key = 'PersonID')

rep = conn.create_edge_frame(
          name = 'ReportsTo',
          schema = [['EmpID', xgt.INT],
                    ['BossID', xgt.INT],
                    ['StartDate', xgt.DATE],
                    ['EndDate', xgt.DATE]],
          source = 'Employee',
          target = 'Employee',
          source_key = 'EmpID',
          target_key = 'BossID')

#-- Load data to the graph in xgtd --
# Use the insert() method for data of a few hundred rows or less;
# for bigger amounts of data, use the load() method with csv files.
emp.insert(
  [[111111101, 'Manny', 98103],
   [111111102, 'Trish', 98108],
   [911111501, 'Frank', 98101],
   [911111502, 'Alice', 98102]
  ])
rep.insert(
  [[111111101, 911111501, '2015-01-03', '2017-04-14'],
   [111111102, 911111501, '2016-04-02', '2017-04-14'],
   [911111502, 911111501, '2016-07-07', '2017-04-14'],
   [111111101, 911111502, '2017-04-15', '3000-12-31'],
   [111111102, 911111502, '2017-04-15', '3000-12-31'],
   [911111501, 911111502, '2017-04-15', '3000-12-31']
  ])

#-- Query data --
conn.drop_frame('Result1')
cmd = '''
  MATCH
    (emp:Employee)-[edge1:ReportsTo]->
    (boss:Employee)-[edge2:ReportsTo]->
    (emp)
  WHERE
    edge1.EndDate <= edge2.StartDate
  RETURN
    emp.PersonID AS Employee1ID,
    boss.PersonID AS Employee2ID,
    edge1.StartDate AS FirstStart,
    edge1.EndDate AS FirstEnd,
    edge2.EndDate AS SecondEnd,
    edge2.StartDate AS SecondStart
  INTO
    Result1
  '''
conn.run_job(cmd)

#-- Results extraction --
ncols = len(emp.schema)
nrows = emp.num_vertices
print('Employee columns: {0} rows: {1} '.format(ncols, nrows))

ncols = len(rep.schema)
nrows = rep.num_edges
print('ReportsTo columns: {0} rows: {1} '.format(ncols, nrows))

r1 = conn.get_table_frame('Result1')
ncols = (r1.schema)
nrows = r1.num_rows
print('Result columns: {0} rows: {1} '.format(ncols, nrows))
print('')

print('--- Result1 ---')
r1dat = r1.get_data(0, 100)
for row in r1dat:
    print(', '.join([str(c) for c in row]))
print('')

#-- Drop all objects --
conn.drop_frame('ReportsTo')
conn.drop_frame('Employee')
conn.drop_frame('Result1')
exception xgt.XgtError(msg, trace='')

Exception to be thrown by xgt in error cases.

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception xgt.XgtNotImplemented(msg, trace='')
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class xgt.Job(conn, job_id)

Represents a user-scheduled Job.

An instance of this object is created by job-scheduling functions like xgt.Connection.run_job and xgt.Connection.schedule_job.

A Job is used as a proxy for a job in the server and allows the user to monitor its execution, possibly cancel it, and learn about its status during and after execution.

end_time

Date and time when the job finished running.

This is a formatted string that has a resolution of seconds.

Type:str
error

User-friendly error message describing the reason a job failed.

Type:str
id

Identifier of the job.

A 64-bit integer value that uniquely identifies a job. It is automatically incremented for each scheduled job over the lifetime of the xgtd server process.

Type:int
start_time

Date and time when the job was scheduled.

This is a formatted string that has a resolution of seconds.

Type:str
status

Status of the job.

Job status
Status Description
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.
Type:str
trace

Very detailed error message for a failed job.

This error message contains the friendly error message and a stack strace for the code that participated in the error.

Type:str
class xgt.Connection(host='127.0.0.1', port=4367, flags=None, rest_port=4368)

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 for RPC calls.
  • flags (dict) –

    Dictionary containing flags. Possible flags are:

    local : boolean
    Use Unix domain sockets to connect to a server on the same machine. The default is False.
    aws_access_key_id : str
    Amazon Access Key ID, used for authentication when loading data files from S3 buckets. The default is an empty string.
    aws_secret_access_key : str
    Amazon Access Key ID, used for authentication when loading data files from S3 buckets. The default is an empty string.
    rpc : boolean

    Deprecated since version 1.0.0.

    If True use the RPC API or if False use the REST API to connect to the server. The default is True.

  • rest_port (int) –

    Deprecated since version 1.0.0.

    Port where the server is listening on for REST requests.

cancel_job(job)

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:job (Job, int) – A Job object or an integer job id to cancel.
Returns:True if the job was cancelled. False if the job already had a status of completed or failed before invoking this function.
Return type:bool

Examples

>>> conn = xgt.Connection()
>>> ... create vertices and edges and run queries ...
>>> print(conn.cancel_job(18))
id:18, status:completed
>>> all_jobs = conn.get_jobs()
>>> for j in all_jobs:
>>> ... conn.cancel_job(j)
create_edge_frame(name, schema, source, target, source_key, target_key)

Create a new EdgeFrame in the server.

An EdgeFrame represents a collection of edges held on the xGT server that share the same property names and types. The source vertex of each edge in an EdgeFrame must belong to the same VertexFrame. This source VertexFrame is identified by the source parameter of this function. The target vertex of each edge in an EdgeFrame must belong to the same VertexFrame. This target VertexFrame is identified by the target parameter.

For each edge in the EdgeFrame, its source vertex is identified by the edge property name given in the parameter source_key, which must be one of the properties listed in the schema. The edge target vertex is identified by the property name given in the parameter target_key, which must be one of the properties listed in the schema.

Parameters:
  • name (str) – Name of edge frame.
  • schema (list of lists) – List of lists associating property names with xGT data types. Each edge in the EdgeFrame will have these properties.
  • source (str or VertexFrame) – The name of a VertexFrame or a VertexFrame object. The source vertex of each edge in this EdgeFrame will belong to this VertexFrame.
  • target (str or VertexFrame) – The name of a VertexFrame or a VertexFrame object. The target vertex of each edge in this EdgeFrame will belong to this VertexFrame.
  • source_key (str) – The edge property name that identifies the source vertex of an edge. This is one of the properties from the schema.
  • target_key (str) – The edge property name that identifies the target vertex of an edge. This is one of the properties from the schema.
Returns:

Frame to the collection of edges.

Return type:

EdgeFrame

Examples

>>> import xgt
>>> conn = xgt.Connection()
>>> conn.create_vertex_frame(
        name = 'Person',
...     schema = [['id', xgt.INT],
...               ['name', xgt.TEXT]],
...     key = 'id')
>>> conn.create_vertex_frame(
        name = 'Company',
...     schema = [['id', xgt.INT],
...               ['size', xgt.TEXT],
...               ['name', xgt.TEXT]],
...     key = 'id')
>>> conn.create_edge_frame(
        name = 'WorksFor',
...     schema = [['srcid', xgt.INT],
...               ['role', xgt.TEXT],
...               ['trgid', xgt.INT]],
...     source = 'Person',
...     target = 'Company',
...     source_key = 'srcid',
...     target_key = 'trgid')
create_table_frame(name, schema)

Create a new TableFrame in the server.

A TableFrame object represents a table held on the xGT server and can be used to retrieve information about it. The TableFrame schema describes the names and data types of table properties.

Parameters:
  • name (str) – Name of table.
  • schema (list of lists) – List of lists associating property names with xGT data types.
Returns:

Frame to the table.

Return type:

TableFrame

Examples

>>> import xgt
>>> conn = xgt.Connection()
>>> conn.create_table_frame(
        name = 'tab1',
...     schema = [['id', xgt.INT],
...               ['name', xgt.TEXT]])
create_vertex_frame(name, schema, key)

Create a new VertexFrame in the server.

A VertexFrame represents a grouping or collection of vertices held on the xGT server, all sharing the same property names and types. This function creates a new frame of vertices on the xGT server and returns a VertexFrame representing it.

Parameters:
  • name (str) – Name of vertex frame.
  • schema (list of lists) – List of lists associating property name with xGT data types Each vertex in the VertexFrame will have these properties.
  • key (str) – The property name used to uniquely identify vertices in the graph. This is the name of one of the properties from the schema and must be unique for each vertex in the frame.
Returns:

Frame to the collection of vertices.

Return type:

VertexFrame

Examples

>>> import xgt
>>> conn = xgt.Connection()
>>> pers_vtx = conn.create_vertex_frame(
                   name = 'Person',
...                schema = [['id', xgt.INT],
...                          ['name', xgt.TEXT]],
...                key = 'id')
drop_frame(frame)

Drop a VertexFrame, EdgeFrame, or TableFrame using its name.

Parameters:frame (str, VertexFrame, EdgeFrame, or TableFrame) – Frame or name of frame to drop on xGT server
Returns:True if frame was found and dropped and False if frame was not found.
Return type:bool
get_edge_frame(name)

Get an EdgeFrame object that allows interaction with a collection of edges.

An EdgeFrame represents a collection of edges held on the xGT server and can be used to retrieve information about them. EdgeFrame.get_data_pandas() and EdgeFrame.get_data() are used to retrieve member edges. Edge edge in an EdgeFrame shares the same properties, described in EdgeFrame.schema.

Parameters:name (str) – EdgeFrame name.
Returns:Frame to the collection of edges.
Return type:EdgeFrame

Examples

>>> conn = xgt.Connection()
>>> ... create graph and run queries ...
>>> e = conn.get_edge_frame('WorksFor')
>>> print(str(e))
{
    'name': 'WorksFor',
    'source': 'Person',
    'target': 'Company',
    'schema': [
        ['srcid', 'int'],
        ['trgid', 'int']],
    'source_key' : 'srcid',
    'target_key' : 'trgid'
}
>>> edges = e.get_data_pandas()
get_edge_frames(names=None, graph=None)

Get a list of EdgeFrame objects present in the xGT server.

An EdgeFrame represents a collection of edges held on the xGT server and can be used to retrieve information about them. EdgeFrame.get_data_pandas() and EdgeFrame.get_data() are used to retrieve member edges. Edge edge in an EdgeFrame shares the same properties, described in EdgeFrame.schema.

Parameters:names (list of strings or None) – If a list, the list of names of edge frames to retrieve. If None, all edge frames are returned.
Returns:EdgeFrame objects present in the server.
Return type:list

Examples

>>> conn = xgt.Connection()
>>> print [f.name for f in conn.get_edge_frames()]
['RelatedTo', 'WorksFor']
get_jobs(jobids=None)

Get a list of Job objects, each representing the state of the job on the server at the point in time of the invocation of this function.

Parameters:jobids (list of ints) – A list of job ids for which to return Job objects. By default all jobs are returned.
Returns:A list of Job objects, each representing the state of a job in the server.
Return type:list

Examples

>>> conn = xgt.Connection()
>>> ... create vertices and edges and run queries ...
>>> all_jobs = conn.get_jobs()
>>> for j in all_jobs:
>>> ... print j
id:6, status:completed
id:7, status:completed
id:8, status:running
get_table_frame(name)

Get a TableFrame object that allows interaction with a table present in the xGT server.

A TableFrame object allows for interaction with a table present in the xGT server. For example, a table may be created by a MATCH query and may contain query results. It may also be explicitly created with Connection.create_table_frame().

Parameters:name (str) – Table name.
Returns:Frame to the table.
Return type:TableFrame

Examples

>>> conn = xgt.Connection()
>>> ... create graph and run queries ...
>>> t = conn.get_table_frame('Employee_table')
>>> print(str(t))
{
    'name': 'Employee_table',
    'schema': [
        ['PersonID', 'int'],
        ['Name', 'text'],
        ['PostalCode', 'int']]
}
>>> qr1 = 'MATCH (a:Employee) RETURN a.PersonID INTO Result1'
>>> conn.run_job(qr1)
>>> result1_table = conn.get_table_frame('Result1')
>>> num_results = result1_table.num_rows
>>> result1_data = result1_table.get_data_pandas()
get_table_frames(names=None)

Get a list of TableFrame objects present in the server.

A TableFrame object allows for interaction with a table present in the xGT server. For example, a table may be created by a MATCH query and may contain query results. It may also be explicitly created with Connection.create_table_frame().

Parameters:names (list of strings or None) – If a list, the list of names of tables frames to retrieve. If None, all table frames are returned.
Returns:TableFrame objects representing tables present in the server.
Return type:list

Examples

>>> conn = xgt.Connection()
>>> ... create graph
>>> qr1 = 'MATCH (a:Employee) RETURN a.PersonID INTO Result1'
>>> conn.run_job(qr1)
>>> table_frames = conn.get_table_frames()
>>> print [f.name for f in table_frames]
['Employee_table', 'ReportsTo_table', 'Result1']
>>> result1_data = table_frames[2].get_data_pandas()
get_vertex_frame(name)

Get a VertexFrame object that allows interaction with a collection of vertices.

A VertexFrame represents a collection of vertices held on the xGT server and can be used to retrieve information about them. VertexFrame.get_data_pandas() and VertexFrame.get_data() are used to retrieve member vertices. Each vertex in a VertexFrame shares the same properties, described in VertexFrame.schema. Each vertex in a VertexFrame is uniquely identified by the property listed in VertexFrame.key.

Parameters:name (str) – VertexFrame name.
Returns:Frame to the collection of vertices.
Return type:VertexFrame

Examples

>>> conn = xgt.Connection()
>>> v = conn.get_vertex_frame('Person')
>>> print(str(v))
{
    'name': 'Person',
    'key': 'id',
    'schema': [
        ['id', 'int'],
        ['name', 'text']],
}
>>> print(str(v.num_vertices))
101
>>> vertices = v.get_data_pandas()
get_vertex_frames(names=None)

Get a list of VertexFrame objects present in the xGT server.

A VertexFrame represents a collection of vertices held on the xGT server and can be used to retrieve information about them. VertexFrame.get_data_pandas() and VertexFrame.get_data() are used to retrieve member vertices. Each vertex in a VertexFrame shares the same properties, described in VertexFrame.schema. Each vertex in a VertexFrame is uniquely identified by the property listed in VertexFrame.key.

Parameters:names (list of strings or None) – If a list, the list of names of vertex frames to retrieve. If None, all vertex frames are returned.
Returns:VertexFrame objects present in the server.
Return type:list

Examples

>>> conn = xgt.Connection()
>>> print [f.name for f in conn.get_vertex_frames()]
['Company', 'Person']
>>> print [f.num_vertices for f in conn.get_vertex_frames()]
[3, 101]
run_job(query, optlevel=None, timeout=None)

Run a TQL query as a job. This function blocks until the job stops running.

Parameters:
  • queries (str) – One TQL query string.
  • 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:

A Job object for the query.

Return type:

Job

Raises:

XgtError – If the query is not a string (str) or the query text is larger than 209,000 characters.

Examples

>>> conn = xgt.Connection()
>>> ... create vertices and edges ...
>>> job = conn.run_job('MATCH (a:Employee) RETURN a.PersonID INTO Result1')
>>> print(job)
id:20, status:completed
>>> conn.run_job('MATCH (a) RETURN a.id INTO Result1')
...
xgt.common.XgtError: Failed jobs:
id: 22
error:
VertexTypeManager: No object registered with this ObjectID 18446744073709551615
schedule_job(query, optlevel=None)

Schedule a TQL query as a job. This function returns immediately after scheduling the job.

Parameters:
  • query (str) – One TQL query string.
  • 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:

A Job object representing the job that has been scheduled.

Return type:

Job

Raises:

XgtError – If the query is not a string (str) or the query text is larger than 209,000 characters.

Examples

>>> conn = xgt.Connection()
>>> ... create vertices and edges ...
>>> query = 'MATCH (a:Employee) RETURN a.PersonID INTO Result1'
>>> job = conn.schedule_job(query)
>>> print(job)
id:25, status:scheduled
server_version

Obtains the current product version from the server.

Returns:Version number.
Return type:str
set_optimization_level(optlevel=2)

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 is 2’.

wait_for_job(job, timeout=None)

Wait for a job. This function blocks until the job stops running.

Parameters:
  • job (Job, int) – A Job object or an integer job id.
  • timeout (int) – Number of seconds each job is allowed to execute before being automatically cancelled. Optional. Default=None (no timeout).
Returns:

A Job object representing the state of the job on the server.

Return type:

Job

Raises:

XgtError – If the query 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.Connection()
>>> ... create vertices and edges ...
>>> 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)
>>> jb1 = conn.wait_for_job(jb1)
>>> print(jb1)
id:31, status:completed
>>> jb2 = conn.wait_for_job(jb2)
>>> print(jb2)
id:32, status:completed
class xgt.VertexFrame(conn, obj)

VertexFrame objects represent a collection of vertices held on the xGT server and can be used to retrieve information about them. These objects are returned by the Connection.get_vertex_frame() method and the Connection.create_vertex_frame() method.

Each vertex in a VertexFrame shares the same properties, described in VertexFrame.schema. Each vertex in a VertexFrame is uniquely identified by the property listed in VertexFrame.key.

Parameters:
  • conn (Connection) – An open connection to an xGT server.
  • obj (json) – Internal vertex structure expressed in JSON objects.

Examples

>>> import xgt
>>> conn = xgt.Connection()
>>> v1 = conn.create_vertex_frame(
...          name = 'Person',
...          schema = [['id', xgt.INT],
...                    ['name', xgt.TEXT]],
...          key = 'id')
>>> v2 = conn.get_vertex_frame('Company') #Company is an existing vertex type
>>> print(v1.name)
get_data(offset=0, length=None)

Returns frame data starting at a given offset and spanning a given length.

Parameters:
  • offset (int) – Position (index) of the first row to be retrieved. Optional. Default=0.
  • length (int) – Maximum number of rows to be retrieved starting from the row indicated by offset. A value of ‘None’ means ‘all rows’ on and after the offset. Optional. Default=None.
Returns:

Return type:

list of lists

get_data_pandas(offset=0, length=None)

Returns a Pandas DataFrame containing frame data starting at a given offset and spanning a given length.

Parameters:
  • offset (int) – Position (index) of the first row to be retrieved. Optional. Default=0.
  • length (int) – Maximum number of rows to be retrieved starting from the row indicated by offset. A value of ‘None’ means ‘all rows’ on and after the offset. Optional. Default=None.
Returns:

Return type:

Pandas DataFrame

insert(data)

Inserts data rows. The properties of the new data must match the schema in both order and type.

Parameters:data (list or Pandas dataframe) – Data represented by a list of lists of data items or by a Pandas Dataframe.
key

Gets the property name that uniquely identifies vertices of this type.

Type:str
load(paths, headerMode=0)

Loads data from a CSV file in the path and the computer indicated by the path.

Parameters:
  • paths (list) –

    Paths to the CSV files.

    Syntax for one CSV file path
    Resource type Path syntax
    local to python: ’<path to csv file>’ ‘xgt://<path to csv file>’
    xgtd computer: ’xgtd://<path to csv file>’
    AWS s3: ’s3://<path to csv file>’
    https site: https://<path to csv file>’
    http site: http://<path to csv file>’
    ftps server: ’ftps://<path to csv file>’
    ftp server: ftp://<path to csv file>’
  • headerMode (str) –
    Indicates if the files contain headers:
    • HeaderMode.NONE
    • HeaderMode.IGNORE
    • HeaderMode.NORMAL
    • HeaderMode.STRICT

    Optional. Default=HeaderMode.NONE.

name

Name of the table.

Type:str
num_rows

Gets the number of rows of the table.

Type:int
num_vertices

Gets the number of vertices in the VertexFrame.

Type:int
save(path, offset=0, length=None, headers=False)

Writes the rows from the frame to a CSV file in the path and the computer indicated by the path.

Parameters:
  • path (str) –

    Path to the CSV file.

    Syntax for one CSV file path
    Resource type Path syntax
    local to python: ’<path to csv file>’ ‘xgt://<path to csv file>’
    xgtd computer: ’xgtd://<path to csv file>’
  • offset (int) – Position (index) of the first row to be retrieved. Optional. Default=0.
  • length (int) – Maximum number of rows to be retrieved. Optional. Default=None.
  • headers (boolean) – Indicates if headers should be added. Optional. Default=False.
schema

Gets the property names and types of the table.

Type:list of lists
class xgt.EdgeFrame(conn, obj)

EdgeFrame objects represent a collection of edges held on the xGT server and can be used to retrieve information about them. These objects are returned by the Connection.get_edge_frame() method or by the Connection.create_edge_frame() method. Edge edge in an EdgeFrame shares the same properties, described in EdgeFrame.schema.

The source vertex of each edge in an EdgeFrame must belong to the same VertexFrame. This name of this VertexFrame is given by EdgeFrame.source_name. The targe vertex of each edge in an EdgeFrame must belong to the same VertexFrame. This name of this VertexFrame is given by EdgeFrame.target_name.

For each edge in the EdgeFrame, its source vertex is identified by the edge property name given by EdgeFrame.source_key, which is be one of the properties listed in the schema. The edge target vertex is identified by the property name given by EdgeFrame.target_key.

Parameters:
  • conn (Connection) – An open connection to an xGT server.
  • obj (json) – Internal edge structure expressed in JSON objects.

Examples

>>> import xgt
>>> conn = xgt.Connection()
>>> e1 = conn.create_edge_frame(
...          name = 'WorksFor',
...          schema = [['srcid', xgt.INT],
...                    ['role', xgt.TEXT],
...                    ['trgid', xgt.INT]],
...          source = 'Person',
...          target = 'Company',
...          source_key = 'srcid',
...          target_key = 'trgid')
>>> e2 = conn.get_edge_frame('RelatedTo') #RelatedTo is an existing edge type
>>> print(e1.name)
get_data(offset=0, length=None)

Returns frame data starting at a given offset and spanning a given length.

Parameters:
  • offset (int) – Position (index) of the first row to be retrieved. Optional. Default=0.
  • length (int) – Maximum number of rows to be retrieved starting from the row indicated by offset. A value of ‘None’ means ‘all rows’ on and after the offset. Optional. Default=None.
Returns:

Return type:

list of lists

get_data_pandas(offset=0, length=None)

Returns a Pandas DataFrame containing frame data starting at a given offset and spanning a given length.

Parameters:
  • offset (int) – Position (index) of the first row to be retrieved. Optional. Default=0.
  • length (int) – Maximum number of rows to be retrieved starting from the row indicated by offset. A value of ‘None’ means ‘all rows’ on and after the offset. Optional. Default=None.
Returns:

Return type:

Pandas DataFrame

insert(data)

Inserts data rows. The properties of the new data must match the schema in both order and type.

Parameters:data (list or Pandas dataframe) – Data represented by a list of lists of data items or by a Pandas Dataframe.
load(paths, headerMode=0)

Loads data from a CSV file in the path and the computer indicated by the path.

Parameters:
  • paths (list) –

    Paths to the CSV files.

    Syntax for one CSV file path
    Resource type Path syntax
    local to python: ’<path to csv file>’ ‘xgt://<path to csv file>’
    xgtd computer: ’xgtd://<path to csv file>’
    AWS s3: ’s3://<path to csv file>’
    https site: https://<path to csv file>’
    http site: http://<path to csv file>’
    ftps server: ’ftps://<path to csv file>’
    ftp server: ftp://<path to csv file>’
  • headerMode (str) –
    Indicates if the files contain headers:
    • HeaderMode.NONE
    • HeaderMode.IGNORE
    • HeaderMode.NORMAL
    • HeaderMode.STRICT

    Optional. Default=HeaderMode.NONE.

name

Name of the table.

Type:str
num_edges

Gets the number of edges of the edge type.

Type:int
num_rows

Gets the number of rows of the table.

Type:int
save(path, offset=0, length=None, headers=False)

Writes the rows from the frame to a CSV file in the path and the computer indicated by the path.

Parameters:
  • path (str) –

    Path to the CSV file.

    Syntax for one CSV file path
    Resource type Path syntax
    local to python: ’<path to csv file>’ ‘xgt://<path to csv file>’
    xgtd computer: ’xgtd://<path to csv file>’
  • offset (int) – Position (index) of the first row to be retrieved. Optional. Default=0.
  • length (int) – Maximum number of rows to be retrieved. Optional. Default=None.
  • headers (boolean) – Indicates if headers should be added. Optional. Default=False.
schema

Gets the property names and types of the table.

Type:list of lists
source_key

The edge property name that identifies the source vertex of an edge.

Type:str
source_name

Gets the name of the source vertex frame.

Type:str
target_key

The edge property name that identifies the target vertex of an edge.

Type:str
target_name

Gets the name of the target vertex frame.

Type:str
class xgt.TableFrame(conn, obj)

TableFrame objects represent a table held on the xGT server and can be used to retrieve information about it. These objects are returned with the Connection.get_table_frame() and Connection.create_table_frame() methods, not directly instantiated. A table may also be created by a MATCH query and may contain query results.

Parameters:
  • conn (Connection) – An open connection to an xGT server.
  • obj (json) – Internal table structure expressed in JSON objects.

Examples

>>> import xgt
>>> conn = xgt.Connection()
>>> ... run query and store results in table01
>>> t = conn.get_table_frame('table01')
>>> print(t.name)
get_data(offset=0, length=None)

Returns frame data starting at a given offset and spanning a given length.

Parameters:
  • offset (int) – Position (index) of the first row to be retrieved. Optional. Default=0.
  • length (int) – Maximum number of rows to be retrieved starting from the row indicated by offset. A value of ‘None’ means ‘all rows’ on and after the offset. Optional. Default=None.
Returns:

Return type:

list of lists

get_data_pandas(offset=0, length=None)

Returns a Pandas DataFrame containing frame data starting at a given offset and spanning a given length.

Parameters:
  • offset (int) – Position (index) of the first row to be retrieved. Optional. Default=0.
  • length (int) – Maximum number of rows to be retrieved starting from the row indicated by offset. A value of ‘None’ means ‘all rows’ on and after the offset. Optional. Default=None.
Returns:

Return type:

Pandas DataFrame

insert(data)

Inserts data rows. The properties of the new data must match the schema in both order and type.

Parameters:data (list or Pandas dataframe) – Data represented by a list of lists of data items or by a Pandas Dataframe.
load(paths, headerMode=0)

Loads data from a CSV file in the path and the computer indicated by the path.

Parameters:
  • paths (list) –

    Paths to the CSV files.

    Syntax for one CSV file path
    Resource type Path syntax
    local to python: ’<path to csv file>’ ‘xgt://<path to csv file>’
    xgtd computer: ’xgtd://<path to csv file>’
    AWS s3: ’s3://<path to csv file>’
    https site: https://<path to csv file>’
    http site: http://<path to csv file>’
    ftps server: ’ftps://<path to csv file>’
    ftp server: ftp://<path to csv file>’
  • headerMode (str) –
    Indicates if the files contain headers:
    • HeaderMode.NONE
    • HeaderMode.IGNORE
    • HeaderMode.NORMAL
    • HeaderMode.STRICT

    Optional. Default=HeaderMode.NONE.

name

Name of the table.

Type:str
num_rows

Gets the number of rows of the table.

Type:int
save(path, offset=0, length=None, headers=False)

Writes the rows from the frame to a CSV file in the path and the computer indicated by the path.

Parameters:
  • path (str) –

    Path to the CSV file.

    Syntax for one CSV file path
    Resource type Path syntax
    local to python: ’<path to csv file>’ ‘xgt://<path to csv file>’
    xgtd computer: ’xgtd://<path to csv file>’
  • offset (int) – Position (index) of the first row to be retrieved. Optional. Default=0.
  • length (int) – Maximum number of rows to be retrieved. Optional. Default=None.
  • headers (boolean) – Indicates if headers should be added. Optional. Default=False.
schema

Gets the property names and types of the table.

Type:list of lists

General

Functions or classes used often to interact with the server.

Connection([host, port, flags, rest_port]) Connection to the server with functionality to create, change, and remove graph structures and run jobs.
Job(conn, job_id) Represents a user-scheduled Job.

Data Access and Manipulation

Classes used to represent objects that exist on the server-side that enable users to retrieve data.

VertexFrame(conn, obj) VertexFrame objects represent a collection of vertices held on the xGT server and can be used to retrieve information about them.
EdgeFrame(conn, obj) EdgeFrame objects represent a collection of edges held on the xGT server and can be used to retrieve information about them.
TableFrame(conn, obj) TableFrame objects represent a table held on the xGT server and can be used to retrieve information about it.