autodrive.connection
¶
Module Contents¶
Classes¶
Provides a connection to the Google Drive api, and methods to send requests |
|
Provides a connection to the Google Sheets api, and methods to send requests |
- class autodrive.connection.DriveConnection(*, auth_config=None, api_version='v3')¶
Provides a connection to the Google Drive api, and methods to send requests to it.
This class is documented primarily for reference, if you want to connect to Google Drive, it’s easier to just use a
Drive
instance.- Parameters
auth_config (AuthConfig, optional) – Optional custom AuthConfig object, defaults to None.
api_version (str, optional) – The version of the Drive api to connect to, defaults to “v3”.
- google_obj_types¶
- find_object(self, obj_name, obj_type, shared_drive_id=None)¶
Searches for a Google Drive Object via the connected api.
- Parameters
obj_name (str) – The name of the object, or part of its name.
obj_type (Literal["sheet", "folder"]) – The type of object to restrict the search to.
shared_drive_id (str, optional) – The id of a Shared Drive to search within, if desired, defaults to None.
- Returns
A list of object properties, if any matches are found.
- Return type
List[Dict[str, Any]]
- create_object(self, obj_name, obj_type, parent_id=None)¶
Creates a file or folder via the Google Drive connection.
- Parameters
obj_name (str) – The desired name of the object to create.
obj_type (Literal["sheet", "folder"]) – The type of object to create.
parent_id (str, optional) – The id of the folder or shared drive to create the object within, defaults to None.
- Returns
The new id of the created object.
- Return type
str
- delete_object(self, object_id)¶
Deletes the passed Google object id from the connected Google Drive.
- Parameters
object_id (str) – A Google object id.
- Return type
None
- property auth(self)¶
- Returns
The AuthConfig passed to this Connection object, or the AuthConfig that was generated automatically upon this Connection’s instantiation.
- Return type
- static get_creds_from_env()¶
Checks if necessary credential and token information has been specified in environment variables and uses that information to generate a Credentials object. Can be used to bypass needing credentials files saved locally.
- Returns
A prepped Credentials object, ready to be slotted into more specific connections, if appropriate environment variables were found, otherwise None.
- Return type
Credentials, optional
- class autodrive.connection.SheetsConnection(*, auth_config=None, api_version='v4')¶
Provides a connection to the Google Sheets api, and methods to send requests to it.
This class is documented primarily for reference, if you want to connect to Google Sheets, it’s easier to just use a View.
- Parameters
auth_config (AuthConfig, optional) – Optional custom AuthConfig object, defaults to None.
api_version (str, optional) – The version of the Sheets api to connect to, defaults to “v4”.
- google_obj_types¶
- execute_requests(self, spreadsheet_id, requests)¶
Sends the passed list of request dictionaries to the Sheets api to be applied to the spreadsheet_id via batch update.
- Parameters
spreadsheet_id (str) – The id of the Google Sheet to update.
requests (List[Dict[str, Any]]) – A list of dictionaries formatted as requests.
- Returns
The resulting response from the Sheets api as a dictionary.
- Return type
Dict[str, Any]
- get_properties(self, spreadsheet_id)¶
Gets the metadata properties of the indicated Google Sheet.
- Parameters
spreadsheet_id (str) – The id of the Google Sheet to collect properties from.
- Returns
A dictionary of the Google Sheet’s properties.
- Return type
Dict[str, Any]
- get_data(self, spreadsheet_id, ranges=None)¶
Collects data from cells in the passed spreadsheet.
- Parameters
spreadsheet_id (str) – The id of the Google Sheet to collect data from.
ranges (List[str], optional) – A list of range strings (e.g. Sheet1!A1:C3), defaults to None, which prompts get_data to fetch all data from all cells.
- Returns
The collected data from the spreadsheet, raw and unparsed.
- Return type
Dict[str, Any]
- property auth(self)¶
- Returns
The AuthConfig passed to this Connection object, or the AuthConfig that was generated automatically upon this Connection’s instantiation.
- Return type
- static get_creds_from_env()¶
Checks if necessary credential and token information has been specified in environment variables and uses that information to generate a Credentials object. Can be used to bypass needing credentials files saved locally.
- Returns
A prepped Credentials object, ready to be slotted into more specific connections, if appropriate environment variables were found, otherwise None.
- Return type
Credentials, optional