autodrive._view

Module Contents

Classes

Formatting

Formatting objects contain methods for adding various update format requests

CellFormatting

Contains methods for generating format requests that update cell properties.

GridFormatting

Contains methods for generating format requests that update grid properties.

TextFormatting

Contains methods for generating format requests that update the properties of

GSheetView

Abstract base class for the different ways of viewing a Google Sheet.

Component

Base class for Tab and Range.

Attributes

T

FC

FG

FT

autodrive._view.T
autodrive._view.FC
autodrive._view.FG
autodrive._view.FT
exception autodrive._view.NoConnectionError(vtype, *args)

Error thrown when attempting to connect via a SheetsConnection that does not exist.

Initialize self. See help(type(self)) for accurate signature.

Parameters
class args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception autodrive._view.OutputError

Error thrown when something goes wrong when attempting to write values to a file.

Initialize self. See help(type(self)) for accurate signature.

class args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class autodrive._view.Formatting(parent)

Formatting objects contain methods for adding various update format requests to their parent Component.

Parameters

parent (Component[Any, Any, Any]) – A Component object.

add_request(request)

Adds the passed request to the Formatting object’s parent component.

Parameters

request (Dict[str, Any]) – An api-ready request.

Return type

None

ensure_full_range(rng=None)

Convenience method for ensuring that all requests generated by this Formatting object have a FullRange attached to them, if one isn’t manually supplied.

Parameters

rng (FullRange | str, optional) – A manually generated FullRange, defaults to None.

Returns

The passed FullRange, or a range generated from the Formatting object’s parent Component.

Return type

FullRange

class autodrive._view.CellFormatting(parent)

Contains methods for generating format requests that update cell properties.

Parameters

parent (Component[Any, Any, Any]) – A Component object.

add_request(request)

Adds the passed request to the Formatting object’s parent component.

Parameters

request (Dict[str, Any]) – An api-ready request.

Return type

None

ensure_full_range(rng=None)

Convenience method for ensuring that all requests generated by this Formatting object have a FullRange attached to them, if one isn’t manually supplied.

Parameters

rng (FullRange | str, optional) – A manually generated FullRange, defaults to None.

Returns

The passed FullRange, or a range generated from the Formatting object’s parent Component.

Return type

FullRange

class autodrive._view.GridFormatting(parent)

Contains methods for generating format requests that update grid properties.

Parameters

parent (Component[Any, Any, Any]) – A Component object.

add_request(request)

Adds the passed request to the Formatting object’s parent component.

Parameters

request (Dict[str, Any]) – An api-ready request.

Return type

None

ensure_full_range(rng=None)

Convenience method for ensuring that all requests generated by this Formatting object have a FullRange attached to them, if one isn’t manually supplied.

Parameters

rng (FullRange | str, optional) – A manually generated FullRange, defaults to None.

Returns

The passed FullRange, or a range generated from the Formatting object’s parent Component.

Return type

FullRange

class autodrive._view.TextFormatting(parent)

Contains methods for generating format requests that update the properties of text in one or more cells.

Parameters

parent (Component[Any, Any, Any]) – A Component object.

add_request(request)

Adds the passed request to the Formatting object’s parent component.

Parameters

request (Dict[str, Any]) – An api-ready request.

Return type

None

ensure_full_range(rng=None)

Convenience method for ensuring that all requests generated by this Formatting object have a FullRange attached to them, if one isn’t manually supplied.

Parameters

rng (FullRange | str, optional) – A manually generated FullRange, defaults to None.

Returns

The passed FullRange, or a range generated from the Formatting object’s parent Component.

Return type

FullRange

class autodrive._view.GSheetView(gsheet_id, *, auth_config=None, sheets_conn=None, autoconnect=True)

Abstract base class for the different ways of viewing a Google Sheet.

Parameters
  • gsheet_id (str) – The id string of the target Google Sheet that the View is attached to.

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

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

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]

class autodrive._view.Component(*, gsheet_range, gsheet_id, tab_id, grid_formatting, text_formatting, cell_formatting, auth_config=None, sheets_conn=None, autoconnect=True)

Base class for Tab and Range.

Parameters
  • gsheet_id (str) – The id string of the target Google Sheet that the View is attached to.

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

  • gsheet_range (autodrive.interfaces.FullRange) –

  • tab_id (int) –

  • grid_formatting (Type[FG]) –

  • text_formatting (Type[FT]) –

  • cell_formatting (Type[FC]) –

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 format_grid: FG

Returns: FG: The GridFormatting subclass associated with this Component type.

Return type

FG

property format_text: FT

Returns: FT: The TextFormatting subclass associated with this Component type.

Return type

FT

property format_cell: FC

Returns: FC: The CellFormatting subclass associated with this Component type.

Return type

FC

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

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]