Google Sheets

Class which allows for Google Sheets to be used as paramater set database.

Note: if you have data in the first row, you must have entries in some other row.

class dapt.db.sheets.Sheet(*args, **kwargs)

Bases: dapt.db.base.Database

An interface for accessing and setting paramater set data. You must either provide a Config object or client_id and client_secret.

Keyword Arguments:
 
  • config (Config) – A Config object which contains the client_id and client_secret.
  • spreedsheet_id (str) – the Google Sheets ID
  • creds (str) – the path to the file containing the Google API credentials. Default is credentials.json.
  • sheet_id (int) – the the sheet id to use. 0 is used if no value is givin for sheet_title, sheet_id or in the Config
  • sheet_title (str) – the title of the sheet to use
get_key_index(column_key)

Get the column index given the key.

Parameters:column_key (str) – the key to find the index of
Returns:The index or -1 if it could not be determined.
get_keys()

Get the keys of the paramater set

Returns:Array of strings with each element being a key (order is preserved if possible)
get_row_index(column_key, row_value)

Get the row index given the column to look through and row value to match to.

Parameters:
  • column_key (str) – the key to find the index of
  • row_value (str) – the value of the cell to fine
Returns:

The index or -1 if it could not be determined.

get_table()

Get the table from the database.

Returns:An array with each element being a dictionary of the key-value pairs for the row in the database.
update_cell(row_id, key, value)

Get the keys of the paramater set

Parameters:
  • row_id (int) – the row id to replace
  • key (str) – the key of the value to replace
  • value (str) – the value to insert into the cell
Returns:

A boolean that is True if successfully inserted and False otherwise.

update_row(row_index, values)

Get the row of the paramater set

Parameters:
  • row_index (int) – the index of the row to replace (starting from 1). Indices less than 1 will return False. Indices greater than the table length will be appended.
  • values (Dict) – the key-value pairs that should be inserted. If the dictionary contains more values then number of columns, the table will be extended.
Returns:

A boolean that is Trues if successfully inserted and False otherwise.

worksheet(*args, **kwargs)

Get a Google Sheet object. The worksheet id or title are obtained from the Config file or initialization.

Returns:A Google Sheet worksheet