msl.io.readers.gsheets module
Read a Google Sheets spreadsheet.
- class msl.io.readers.gsheets.GSheetsReader(file, **kwargs)[source]
Bases:
Spreadsheet
Read a Google Sheets spreadsheet.
This class simply provides a convenience for reading information from Google spreadsheets. It is not registered as a
Reader
because the information in a spreadsheet is unstructured and therefore one cannot generalize how to parse a spreadsheet to create aRoot
.- Parameters:
Examples
>>> from msl.io import GSheetsReader >>> sheets = GSheetsReader('Google Drive/registers/equipment.gsheet') >>> sheets = GSheetsReader('1TI3pM-534SZ5DQTEZ-7HCI04648f8ZpLGbfHWJu9FSo')
- read(cell=None, sheet=None, as_datetime=True)[source]
Read values from the Google Sheets spreadsheet.
- Parameters:
cell (
str
, optional) – The cell(s) to read. For example,C9
will return a single value andC9:G20
will return all values in the specified range. If not specified then returns all values in the specified sheet.sheet (
str
, optional) – The name of the sheet to read the value(s) from. If there is only one sheet in the spreadsheet then you do not need to specify the name of the sheet.as_datetime (
bool
, optional) – Whether dates should be returned asdatetime
ordate
objects. IfFalse
then dates are returned as a string in the format of the spreadsheet cell.
- Returns:
The value(s) of the requested cell(s).
Examples
>>> sheets.read() [('temperature', 'humidity'), (20.33, 49.82), (20.23, 46.06), (20.41, 47.06), (20.29, 48.32)] >>> sheets.read('B2') 49.82 >>> sheets.read('A:A') [('temperature',), (20.33,), (20.23,), (20.41,), (20.29,)] >>> sheets.read('A1:B1') [('temperature', 'humidity')] >>> sheets.read('A2:B4') [(20.33, 49.82), (20.23, 46.06), (20.41, 47.06)]