Google Drive

Authentication

Config

Usage

class dapt.storage.google_drive.Google_Drive(**kwargs)

Bases: dapt.storage.base.Storage

Download, upload, move, and delete files or folders from Google Drive.

Keyword Arguments:
 
  • creds_path (str) – the path to the file containing the Google API credentials. Default is credentials.json.
  • config (Config) – a Config object with the associated config file to be used
connect()

Allows you to sign into your Google account through the internet browser. This should automatically open the browser up.

Returns:True if the connection was successful and False otherwise.
create_folder(file_id, name)

Create a folder named name in the folder with the file_id given.

Parameters:
  • file_id (str) – The file id of the parent folder to create the new folder in
  • name (str) – What the name of the new folder should be
Returns:

The file metedata if successful and None otherwise.

delete_file(file_id)

Delete the the given file.

Parameters:file_id (str) – The file identification to be downloaded
Returns:True if successful and False otherwise
delete_folder(file_id)

Delete the given folder.

Parameters:file_id (str) – The folder identification to be downloaded
Returns:True if successful and False otherwise
download_file(file_id, folder='.', name=None, overwrite=True)

Download the file at the given file_id to the given path. This will only download binary files such as Microsoft Docs, PDFs, PNGs, MP4, etc. This method is not capable of downloading Google products such as Google Docs and Google Sheets.

Parameters:
  • ile_id (str) – The file identification to be downloaded
  • folder (str) – The directory where the file should be saved
  • name (str) – The name that the file should be saved as. If None is given (default), then the name of the file on the resource will be used.
  • overwrite (bool) – Should the data on your machine be overwritten. True by default.
Returns:

True if successful and False otherwise

download_folder(file_id, folder='.', name=None, overwrite=True)

Download the folder at the given file_id to the given path.

Parameters:
  • ile_id (str) – The file identification to be downloaded
  • folder (str) – The directory where the file should be saved
  • name (str) – The name that the file should be saved as. If None is given (default), then the name of the file on the resource will be used.
  • overwrite (bool) – Should the data on your machine be overwritten. True by default.
Returns:

True if successful and False otherwise

rename_file(file_id, name)

Rename the given file.

Parameters:
  • file_id (str) – The file identification to be downloaded
  • name (str) – The new name of the file or folder
Returns:

True if the file or folder was renamed, False otherwise.

rename_folder(file_id, name)

Rename the given folder.

Parameters:
  • file_id (str) – The folder identification to be downloaded
  • name (str) – The new name of the file or folder
Returns:

True if the file or folder was renamed, False otherwise.

upload_file(file_id, name, folder='.', overwrite=True)

Upload a file to the given folder.

Parameters:
  • file_id (str) – The folder where the file should be saved.
  • name (str) – The name that the file should be uploaded.
  • folder (str) – The directory where the file is stored.
  • overwrite (bool) – Should the data on your machine be overwritten. True by default.
Returns:

True if the upload was successful and False otherwise.

upload_folder(file_id, name, folder='.', overwrite=True)

Upload a folder to the given folder.

Parameters:
  • file_id (str) – The folder where the folder should be saved.
  • name (str) – The name that the file should be uploaded.
  • folder (str) – The directory where the folder is stored.
  • overwrite (bool) – Should the data on your machine be overwritten. True by default.
Returns:

True if the upload was successful and False otherwise.