API Reference

sheetsql

SQL for Google Sheets.

sheetsql.connect(auth_type, **kwargs)

Connect to Google Sheets via gspread oauth or service_account.

Return type

GoogleSheetsConnection

sheetsql.connection

Class to connect to Google Sheets.

class sheetsql.connection.GoogleSheetsConnection(auth_type='service_account', **kwargs)

Wrapper around the gspread package for interracting with Google Sheets.

get_spreadsheet(spreadsheet_id)

Get a specific spreadsheet by its ID.

Return type

Spreadsheet

property spreadsheets

List the spreadsheets the authorized user has access to.

Return type

list

sheetsql.exceptions

Custom exceptions.

exception sheetsql.exceptions.InvalidQueryException

Raises if the table query (tq) is invalid.

exception sheetsql.exceptions.InvalidRowTypeException

Raises if the row type is invalid.

exception sheetsql.exceptions.SpreadsheetNotFoundException

Raises if a spreadsheet is not found.

sheetsql.spreadsheet

Spreadsheet interface.

class sheetsql.spreadsheet.Spreadsheet(client, properties)

Class inheriting the gspread.Spreadsheet class to represent a spreadsheet.

get_worksheet(worksheet_name)

Get specific worksheet by name.

Return type

Worksheet

property worksheets

List the worksheets in the current spreadsheet.

Return type

list

sheetsql.utils

Utility functions.

sheetsql.utils.handle_tq_response(response)

Handle response returned from the table query.

Parameters

response (Response) – Table query response

Raises

InvalidQueryException – if the specified query is invalid

Returns

The table key of the response JSON

Return type

dict

sheetsql.utils.parse_json_from_tq_response(response_text)

Parse the JSON content out of a table query response.

Parameters

response_text (str) – The table query response text

Returns

The table query JSON content

Return type

dict

sheetsql.worksheet

Worksheet interface.

class sheetsql.worksheet.Worksheet(spreadsheet, properties)

Class inheriting the gspread.Worksheet class to represent a worksheet.

all()

Get generator that contains all rows in the spreadsheet.

property column_label_id_map

Get dictionary contaning a map of column label to column identifier.

Return type

dict

property columns

Get columns in the worksheet.

Return type

list

count()

Get number of rows.

Return type

int

property default_row_type

Get default row type returned by query method if the row_type kwarg is not passed in.

property num_columns

Get number of columns in the worksheet.

Return type

int

query(tq, row_type=None)

Query data in the current worksheet using Google’s Table Query (tq) Language.

See https://developers.google.com/chart/interactive/docs/querylanguage for more info