autodrive.tab

Module Contents

Classes

Tab

Provides a connection to a single Google Sheet Tab, its properties, and its

class autodrive.tab.Tab(gsheet_id, tab_title, tab_idx, tab_id, column_count=26, row_count=1000, *, auth_config=None, sheets_conn=None, autoconnect=True)

Provides a connection to a single Google Sheet Tab, its properties, and its data.

Parameters
  • gsheet_id (str) – The id string of the target Google Sheet that the Tab resides in; can be found in the Google Sheet url.

  • tab_title (str) – The name of the Tab.

  • tab_idx (int) – The index (0-based) of the Tab in the Google Sheet.

  • tab_id (int) – The id of the Tab, can be found in the Google Sheet url (after gid=).

  • column_count (int, optional) – The starting number of columns in the Tab, defaults to 26.

  • row_count (int, optional) – The starting number of rows in the Tab, defaults to 1000.

  • auth_config (AuthConfig, optional) – Optional custom AuthConfig, defaults to None.

  • sheets_conn (SheetsConnection, optional) – Optional manually created SheetsConnection, defaults to None.

  • autoconnect (bool, optional) – If you want to instantiate a Tab without immediately checking your authentication credentials and connection to the Google Sheets api, set this to False, defaults to True.

property tab_id(self)
Returns

This Tab’s id. Matches the gid of the parent GSheet’s url.

Return type

int

property format_grid(self)
Returns

An object with grid formatting methods.

Return type

TabGridFormatting

property format_text(self)
Returns

An object with text formatting methods.

Return type

TabTextFormatting

property format_cell(self)
Returns

An object with cell formatting methods.

Return type

TabCellFormatting

property title(self)
Returns

The name of this Tab.

Return type

str

property index(self)
Returns

The (0-based) index location of this Tab among the other Tabs on the parent GSheet.

Return type

int

property column_count(self)
Returns

The number of columns in this Tab.

Return type

int

property row_count(self)
Returns

The number of rows in this Tab.

Return type

int

classmethod from_properties(cls, gsheet_id, properties, auth_config=None, sheets_conn=None, autoconnect=True)

Generates a Tab assigned to the passed gsheet_id with the passed tab properties dictionary from a SheetsConnection.get_properties call.

Unless you have a special use-case, it is probably more trouble than it’s worth to try to instantiate a Tab with this method, as it is designed for use by other Autodrive objects.

Parameters
  • gsheet_id (str) – The id of the parent GSheet.

  • properties (Dict[str, Any]) – A properties dictionary, which must contain index, SheetId, title, and gridProperties keys. The gridProperties must be a dictionary containing columnCount and rowCount keys.

  • auth_config (AuthConfig, optional) – Optional custom AuthConfig, defaults to None.

  • sheets_conn (SheetsConnection, optional) – Optional manually created SheetsConnection, defaults to None.

  • autoconnect (bool, optional) – If you want to instantiate a Tab without immediately checking your authentication credentials and connection to the Google Sheets api, set this to False, defaults to True.

Returns

A Tab with the values from the passed properties dictionary.

Return type

Tab

full_range(self)

Generates a FullRange object corresponding to the full range of the Tab.

Returns

A FullRange from A1:the end of the Tab.

Return type

FullRange

get_data(self, rng=None, value_type=EffectiveVal)

Gets the data from the cells of this Tab.

Note

This method will cause a request to be posted to the relevant Google API immediately.

Parameters
  • rng (FullRange | HalfRange, optional) – An optional range value, to specify a subset of the Tab’s values to get, defaults to None, which fetches all values in the Tab.

  • value_type (GoogleValueType, optional) – Allows you to toggle the type of the values returned by the Google Sheets API. See the dtypes documentation for more info on the different GoogleValueTypes.

Returns

This Tab.

Return type

Tab

write_values(self, data, rng=None)

Adds a request to write data. Tab.commit () to commit the requests.

Parameters
  • data (List[List[Any]]) – The data to write. Each list in the passed data list is a row, with each value in that sublist being a column.

  • rng (FullRange, optional) – A specific range to write to, starting with the top-left-most cell in the range, defaults to None, which will write to the top-left-most cell of the Tab.

Returns

This Tab.

Return type

Tab

classmethod new_tab_request(cls, tab_title, tab_id=None, tab_idx=None, num_rows=1000, num_cols=26)

Creates a dictionary request to create a new tab in a Google Sheet.

Parameters
  • tab_title (str) – The name of the tab.

  • tab_id (int, optional) – The desired id of the tab, which cannot already exist in the Google Sheet, defaults to None, which will allow the Google Sheet to generate the tab_id.

  • tab_idx (int, optional) – The (0-based) index to create the tab at, defaults to None, meaning the tab will be created as the last tab in the Google Sheet.

  • num_rows (int, optional) – The starting number of rows in the new tab, defaults to 1000.

  • num_cols (int, optional) – The starting number of columns in the new tab, defaults to 26.

Returns

A dictionary ready to be passed as a request via a request commit.

Return type

Dict[str, Any]

gen_add_tab_request(self)

Generates a new tab request dictionary for this Tab. Useful when you have manually instantiated a Tab object instead of fetching it and want to add it to the parent GSheet.

Returns

A dictionary ready to be passed as a request via a request commit.

Return type

Dict[str, Any]

create(self)

Convenience method for generating a new tab request based on this Tab and immediately committing it, thus adding it to the parent Google Sheet.

Note

This method will cause a request to be posted to the relevant Google API immediately.

Returns

This Tab.

Return type

Tab

gen_range(self, rng)

Convenience method for generating a new Range object in this Tab.

Parameters

rng (FullRange) – The desired FullRange of the new Range object.

Returns

The newly generated Range.

Return type

Range