autodrive.range

Module Contents

Classes

Range

Provides a connection to the data in a specific range in a Google Sheet Tab.

class autodrive.range.Range(gsheet_range, gsheet_id, tab_title, tab_id, *, auth_config=None, sheets_conn=None, autoconnect=True)

Provides a connection to the data in a specific range in a Google Sheet Tab.

Parameters
  • gsheet_range (FullRange | str) – The range (i.e. A5:C10) to associate with this Range.

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

  • tab_title (str) – The name of the Tab this Range is within.

  • 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 Range without immediately checking your authentication credentials and connection to the Google Sheets api, set this to False, defaults to True.

  • tab_id (int) –

property format_grid: autodrive.formatting.format_rng.RangeGridFormatting

Returns: RangeGridFormatting: An object with grid formatting methods.

Return type

autodrive.formatting.format_rng.RangeGridFormatting

property format_text: autodrive.formatting.format_rng.RangeTextFormatting

Returns: RangeTextFormatting: An object with text formatting methods.

Return type

autodrive.formatting.format_rng.RangeTextFormatting

property format_cell: autodrive.formatting.format_rng.RangeCellFormatting

Returns: RangeCellFormatting: An object with cell formatting methods.

Return type

autodrive.formatting.format_rng.RangeCellFormatting

property tab_id: int

Returns: int: The id of the linked tab.

Return type

int

property range_str: str

The string representation of the range specified by this Component.

Type

str

Return type

str

property range: autodrive.interfaces.FullRange

Returns: FullRange: The FullRange representation of the range specified by this Component.

Return type

autodrive.interfaces.FullRange

property values: List[List[Any]]

Returns: List[List[Any]]: The fetched data values in this Component’s cells.

Return type

List[List[Any]]

property formats: List[List[Dict[str, Any]]]

Returns: List[List[Dict[str, Any]]]: The fetched formatting properties of this Component’s cells.

Return type

List[List[Dict[str, Any]]]

property data_shape: Tuple[int, int]

Returns: Tuple[int, int]: The row length and column width of this Component’s data.

Return type

Tuple[int, int]

property requests: List[Dict[str, Any]]

Returns: List[Dict[str, Any]]: The list of current (uncommitted) requests.

Return type

List[Dict[str, Any]]

property conn: autodrive.connection.SheetsConnection
Returns

The view’s SheetsConnection.

Return type

SheetsConnection

Raises

NoConnectionError – If the view’s connection is null.

property auth: autodrive.interfaces.AuthConfig
Returns

The view’s AuthConfig.

Return type

AuthConfig

Raises

NoConnectionError – If the view’s auth config is null.

property gsheet_id: str

Returns: str: The id of the Google Sheet this view is connected to.

Return type

str

get_data(value_type=EffectiveVal)

Gets the data from the cells of this Range.

Note

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

Parameters

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 Range.

Return type

Range

write_values(data)

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

Parameters

data (Sequence[Sequence[Any] | Dict[str, Any]]) – The data to write. Each sequence or dictionary in the passed data is a row, with each value in that sub-iterable being a column. Dictionary keys will be used as a header row in the written data.

Returns

This Tab.

Return type

Range

to_csv(p, header=None)

Saves values to a csv file.

Parameters
  • p (str | Path) – The path-like for the file to save the data to.

  • header (Sequence[Any], optional) – A header row. If supplied, must be the same number of columns as the data values. Defaults to None.

Return type

None

to_json(p, header=0)

Saves values to a json file, with one json per line.

Parameters
  • p (str | Path) – The path-like for the file to save the data to.

  • header (Sequence[Any] | int) – A header row or the index of a row in the values data to use as the header row. The header will be used as the keys for the json-formatted dictionaries. Defaults to 0, using the first row as the header.

Return type

None

commit()

Commits the amassed requests on this view, sending them to the Sheets api as a batch update request.

Returns

The response from the api.

Return type

Dict[str, Any]

Raises

NoConnectionError – If the view’s SheetsConnection is null.

ensure_full_range(backup, rng=None)

Convenience method for ensuring that a range argument that could be None or a string is always a FullRange.

Parameters
Returns

The passed FullRange, or the backup FullRange.

Return type

FullRange

static gen_alpha_keys(num)

Generates a list of characters from the Latin alphabet a la gsheet/excel headers.

Parameters

num (int) – The desired length of the list.

Returns

A list containing as many letters and letter combos as desired. Can be used to generate sets up to 676 in length.

Return type

List[str]