xgt.TableProxy

class xgt.TableProxy(conn, obj)

TableProxy objects represent a table held on the xGT server and can be used to retrieve information about it. These objects are returned from a Connection object, not directly instantiated.

Parameters:
conn : Service

An open connection to an xGT server.

obj : json

Internal table structure expressed in JSON objects.

Examples

>>> import xgt
>>> conn = xgt.connect()
>>> t = conn.get_table('table01')
>>> print(t.name)
Attributes:
name

str: Name of the table.

schema

CustomDictionary: Set of table columns.

Methods

get_data([offset, length]) Returns table data starting at a given offset and spanning a given length.
get_data_pandas([offset, length]) Returns a Pandas DataFrame containing table data starting at a given offset and spanning a given length.
get_definition() str: Gets the TQL command that could be used to recreate the table.
insert(data) Inserts data rows.
load(paths[, headerMode]) Loads data from a CSV file in the path and the computer indicated by the path.
num_cols() int: Gets the number of columns of the table.
num_rows() int: Gets the number of rows of the table.
save(path[, offset, length, headers]) Writes the rows from the table to a CSV file in the path and the computer indicated by the path.
__init__(conn, obj)

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

Methods

__init__(conn, obj) Initialize self.
get_data([offset, length]) Returns table data starting at a given offset and spanning a given length.
get_data_pandas([offset, length]) Returns a Pandas DataFrame containing table data starting at a given offset and spanning a given length.
get_definition() str: Gets the TQL command that could be used to recreate the table.
insert(data) Inserts data rows.
load(paths[, headerMode]) Loads data from a CSV file in the path and the computer indicated by the path.
num_cols() int: Gets the number of columns of the table.
num_rows() int: Gets the number of rows of the table.
save(path[, offset, length, headers]) Writes the rows from the table to a CSV file in the path and the computer indicated by the path.

Attributes

name str: Name of the table.
schema CustomDictionary: Set of table columns.
get_data(offset=0, length=None)

Returns table 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:
list of lists
get_data_pandas(offset=0, length=None)

Returns a Pandas DataFrame containing table 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:
Pandas DataFrame
get_definition()

str: Gets the TQL command that could be used to recreate the table.

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:

local to python: ‘<absolute path to csv file>’ xgtd computer: ‘xgtd://<absolute path to csv file>’ AWS s3: ‘s3://<absolute path to csv file>’ https site: ‘https://<absolute path to csv file>’ http site: ‘http://<absolute path to csv file>’ ftps server: ‘ftps://<absolute path to csv file>’

headerMode : str
Indicates if the files contain headers:

HeaderMode.NONE HeaderMode.IGNORE HeaderMode.NORMAL HeaderMode.STRICT

Optional. Default=HeaderMode.NONE.

Examples

>>> import xgt
>>> conn = xgt.connect()
>>> ...
>>> t = conn.get_table('table01')
>>> t.load('xgtd:///home/username/file.csv')
name

str: Name of the table.

num_cols()

int: Gets the number of columns of the table.

num_rows()

int: Gets the number of rows of the table.

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

Writes the rows from the table 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:

local to python: ‘<absolute path to csv file>’ xgtd computer: ‘xgtd://<absolute path to csv file>’ AWS s3: ‘s3://<absolute path to csv file>’ https site: ‘https://<absolute path to csv file>’ http site: ‘http://<absolute path to csv file>’ ftps server: ‘ftps://<absolute 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

CustomDictionary: Set of table columns.