autodrive.drive

Module Contents

Classes

Folder

Stores all the necessary properties of a Google Drive Folder and provides

Drive

A one-stop shop for finding and managing Google Drive objects, including

class autodrive.drive.Folder(folder_id, name, *, parents=None, auth_config=None, drive_conn=None, sheets_conn=None)

Stores all the necessary properties of a Google Drive Folder and provides methods for interacting with its subfolders and files.

Parameters
  • folder_id (str) – The id string of the folder.

  • name (str) – The name of the folder.

  • parents (List[str], optional) – A list of the Folder’s parents, usually just its parent folder or parent shared drive, if any, defaults to None, signifying that the folder is at the root of an unshared drive.

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

  • drive_conn (DriveConnection, optional) – Optional manually created DriveConnection, defaults to None

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

property id: str

Returns: str: The id string of the Folder.

Return type

str

property name: str

Returns: str: The name of the Folder.

Return type

str

property parent_ids: List[str]

Returns: List[str]: The list of the Folder’s parents, usually just its parent folder or parent shared drive, if any.

Return type

List[str]

create_folder(folder_name)

Generates a new Folder with this Folder as its parent.

Note

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

Parameters

folder_name (str) – The name of the Folder to create.

Returns

The newly created Folder.

Return type

Folder

create_gsheet(gsheet_name)

Creates a new Google Sheet with this Folder as its parent.

Note

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

Parameters

gsheet_name (str) – The desired name of the new Google Sheet.

Returns

The newly created GSheet.

Return type

GSheet

upload_files(*filepaths)

Uploads files to the folder.

Parameters

*filepaths (Path | str | FileUpload) – An arbitrary number of Path objects, path strings, or FileUpload objects (if you want to convert the file to a Google Drive format (e.g. Docs, Sheets, etc).

Returns

The names of the uploaded files and their new ids in

Google Drive.

Return type

Dict[str, str]

class autodrive.drive.Drive(*, auth_config=None, drive_conn=None, sheets_conn=None)

A one-stop shop for finding and managing Google Drive objects, including folders and Google Sheets.

Note

All the methods on this class will cause a request to be posted to the relevant Google API immediately.

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

  • drive_conn (DriveConnection, optional) – Optional manually created DriveConnection, defaults to None.

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

create_folder(folder_name, parent=None)

Creates a folder in the connected Google Drive.

Parameters
  • folder_name (str) – The desired name of the new folder

  • parent (str | Folder, optional) – The parent folder/id to create this folder within, or the id of the shared drive to create within, defaults to None.

Returns

The newly created Folder.

Return type

Folder

create_gsheet(gsheet_name, parent=None)

Creates a Google Sheet in the connected Google Drive.

Parameters
  • gsheet_name (str) – The desired name of the new Google Sheet.

  • parent (str | Folder, optional) – The parent folder/id to create this gsheet within, or the id of the shared drive to create within, defaults to None.

Returns

The newly created GSheet.

Return type

GSheet

find_gsheet(gsheet_name)

Search for Google Sheets that match the passed name. GSheets found in this way will need to have their properties gathered with a GSheet.fetch () call. To save round trips this method only collects the basic details of the Google Sheets it matches. These properties cannot be gathered via the Google Drive api, unfortunately.

Parameters

gsheet_name (str) – The name (or part of the name) to search for.

Returns

A list of GSheet objects with basic details (id, name) that matched the name parameter.

Return type

List[GSheet]

find_folder(folder_name, shared_drive_id=None)

Search for folders that match the passed name.

Parameters
  • folder_name (str) – The name (or part of the name) to search for.

  • shared_drive_id (str, optional) – The shared drive id to search within, defaults to None

Returns

A list of Folder object that matched the name parameter.

Return type

List[Folder]

upload_files(*filepaths)

Uploads files to the root drive or to a folder.

Note

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

Parameters

*filepaths (Path | str | FileUpload) – An arbitrary number of Path objects, path strings, or FileUpload objects (for more complex cases).

Returns

The names of the uploaded files and their new ids in

Google Drive.

Return type

Dict[str, str]