ConDB Web Access Python API¶
This document describes the Python API for remote access to the ConDB web server.
- class condb.ConDBClient(url, username=None, password=None)¶
- __init__(url, username=None, password=None)¶
Initializes the ConDB client
- Parameters:
url (str) – Server URL prefix
username (str) – Optional username
password (str) – Optional password
- get_data(folder, t0, t1=None, tag=None, tr=None, data_type=None, channels=None, as_named_tuples=False)¶
Get data from folder
- Parameters:
folder (str) – Folder name
t0 (int or float) – Tv to get data for
t1 (int or float) – Optional, if specified, the data will be returned for the t0…t1 time interval
tag (str) – Optional, return data from the tagged database state
tr (datetime or int or float) – Optional, return data for previous state of the database identified with tr
data_type (str) – Optional, return sata for the given data source. Default: “”
channels (list or tuple or int) – If int, return data for single channel If tuple, return data for a range of channels, e.g.: (100, 151) If list, return data for list of channels or channel ranges, e.g.: [10, 15, (23, 27)]
as_named_tuples (bool) – If true, return the data as collections.namedtuple’s. Otherwise, native Python tuples
- Returns:
columns - list of column names generator - producing tuples or collections.namedtuple’s, one per data row
- Return type:
tuple (columns, generator)
- put_data(folder, data, columns, tr=None, data_type=None)¶
Add data to folder. Requires the username and password.
- Parameters:
folder (str) – Folder name
data (list) – List of tuples: [channel, tv, …]. Order of columns after tv is the same as in
columnscolumns (list) – Must begin with [“channel”, “tv”]
data_type (str) – Optional data source, default = “”
tr (datetime or int or float) – Optional Tr to associate the data with. Default = current time
- search_data(folder, tag=None, tr=None, data_type=None, channels=None, conditions=[], as_named_tuples=False)¶
- Search the timeline determined by (tag, tr, data_type) for data rows
matching the conditions expressed in terms of the data column values
- Parameters:
folder (str) – Folder name
tag (str) – Optional, return data from the tagged database state
tr (datetime or int or float) – Optional, return data for previous state of the database identified with tr
data_type (str) – Optional, return sata for the given data source. Default: “”
channels (list or tuple or int) – If int, return data for single channel If tuple, return data for a range of channels, e.g.: (100, 151) If list, return data for list of channels or channel ranges, e.g.: [10, 15, (23, 27)]
conditions (list of tuples) – Conditions cpecified as tuples: (“column_name”, op, value) column_name is a name of a data column op is a string “<”, “<=”, “=”, “!=”, “>=”, “>” value is a string, boolean, numeric or None
as_named_tuples (bool) – If true, return the data as collections.namedtuple’s. Otherwise, native Python tuples
- Returns:
columns - list of column names generator - producing tuples or collections.namedtuple’s, one per data row
- Return type:
tuple (columns, generator)
- tag_state(folder, tag, tr=None, copy_from=None, override=False)¶
Add tag to a database state. Requires the username and password.
- Parameters:
folder (str) – Folder name
tag (str) – Tag to add
tr (datetime or int or float) – Tr, optional. Identifies the database state to tag. Default: current state
copy_from (str) – Tag the same state as an existing tag
override (boolean) – If the tag already exists, move the tag to the new Tr