neuralib.tools.gspread
- neuralib.tools.gspread.SpreadSheetName
spreadsheet name
- neuralib.tools.gspread.WorkPageName
workpage name of the spreadsheet
- neuralib.tools.gspread.DataIndex
data index type
alias of
None|int|str|slice|list[int] |list[str] |ndarray
- class neuralib.tools.gspread.GoogleSpreadSheet[source]
Gspread module wrapper to access google spreadsheet
See also
service_account_path = ... # The path to the service account json file sh = GoogleSpreadSheet('test_sheet', service_account_path) # get a worksheet from the spreadsheet ws = sh[WORK_SHEET_NAME]
- __init__(name, service_account_path, primary_key='Data')[source]
- Parameters:
name (SpreadSheetName) – name of the spreadsheet
service_account_path (PathLike) – The path to the service account json file
primary_key (str | tuple[str, ...]) –
Primary key of the worksheet.
If str type, it must be one of the column name.
If tuple str type, the primary key is join using “_” per row
- property title: str
SpreadSheetName
- property worksheet_list: list[str]
list of
WorkPageName
- has_worksheet(page)[source]
If has the worksheet, implement also in
__contains__()- Parameters:
page (str)
- Return type:
bool
- class neuralib.tools.gspread.GoogleWorkSheet[source]
- __init__(worksheet, primary_key='Data')[source]
- Parameters:
worksheet (gspread.Worksheet) –
gspread.Worksheetprimary_key (str | tuple[str, ...]) –
Primary key of the worksheet.
If str type, it must be one of the column name.
If tuple str type, the primary key is join using “_” per row
- classmethod of(name, page, service_account_path, primary_key='Data')[source]
Get a worksheet from spreadsheet
- Parameters:
name (SpreadSheetName) –
SpreadSheetNamepage (WorkPageName) –
WorkPageNameservice_account_path (PathLike) – The path to the service account json file
primary_key (str | tuple[str, ...]) –
Primary key of the worksheet.
If str type, it must be one of the column name.
If tuple str type, the primary key is join using “_” per row
- Returns:
GoogleWorkSheet- Return type:
Self
- property title: str
WorkPageName
- property headers: list[str]
list of worksheet header
- property primary_key_list: list[str]
list of primary key of the worksheet
- get_range_value(a1_range_notation)[source]
get values from range notation. i.e., B1:S1 to get the list of content.
If get values from 2D, the return order would be first column-wise, then row-wise
- Parameters:
a1_range_notation (str)
- Return type:
list[Any]
- get_cell(data, head, value_render_option='FORMATTED_VALUE')[source]
Get data from a cell
- Parameters:
data (None | int | str | slice | list[int] | list[str] | ndarray) –
DataIndexhead (str) – header name
value_render_option (Literal['FORMATTED_VALUE', 'UNFORMATTED_VALUE', 'FORMULA']) –
VALUE_RENDER_OPT: {‘FORMATTED_VALUE’, ‘UNFORMATTED_VALUE’, ‘FORMULA’}
- Returns:
- neuralib.tools.gspread.upload_dataframe_to_spreadsheet(df, gspread_name, worksheet_name, service_account_path, primary_key='Data')[source]
Upload a dataframe to a gspread worksheet
- Parameters:
df (DataFrame) – polars or pandas DataFrame
gspread_name (SpreadSheetName) – spreadsheet name
worksheet_name (WorkPageName) – worksheet name under the spreadsheet
service_account_path (Path | None) – The path to the service account json file.
primary_key (str | tuple[str, ...]) – Primary key of the worksheet. If str type, it must be one of the column name. If tuple str type, the primary key is join using “_” per row
- Return type:
None