fusetools.gsuite_tools.GDrive

class fusetools.gsuite_tools.GDrive[source]

Bases: object

Functions for interacting with Google Drive.

../_images/googledrive1.jpeg

Methods

authorize_credentials

Creates an authorized credentials object for Google Drive.

create_service_serv_acct

Creates a GDrive authenticated credentials object.

create_upload_folder

Creates a folder in Google Drive.

download_file

Downloads a file from a Google Drive account.

get_all_google_items

Get all files in a Google Drive (or folder if specified).

get_file_revisions

param file_id

upload_files

Uploads files to a folder on Google Drive.

classmethod authorize_credentials(cred_path, token_path)[source]

Creates an authorized credentials object for Google Drive.

Parameters
  • cred_path – Local path to GSuite credentials object.

  • token_path – Local path to GSuite authorization token.

Returns

Authorized credentials object for GSuite.

classmethod create_service_serv_acct(member_acct_email, token_path)[source]

Creates a GDrive authenticated credentials object.

Parameters
  • member_acct_email – GDrive service acct email address.

  • token_path – Path to GDrive authentication token.

Returns

Return GDrive authenticated credentials object.

classmethod create_upload_folder(folder_name, credentials, overwrite_folder=False, parent_id=None)[source]

Creates a folder in Google Drive.

Parameters
  • folder_name – Name of folder to create.

  • credentials – GSuite credentials object.

  • overwrite_folder – Whether or not to delete and re-create the folder.

  • parent_id – Id of parent folder (optional).

Returns

Created folder information.

classmethod download_file(file_id, file_name, credentials, save_local=False)[source]

Downloads a file from a Google Drive account.

Parameters
  • file_name – Name of file to download from Google Drive.

  • save_local – whether to return file in bytes or save locally (default is bytes).

  • file_id – ID for Google Drive file.

  • credentials – GSuite credentials object.

Returns

Downloaded file from Google Drive.

classmethod get_all_google_items(credentials, page_size=None, folder_id=None)[source]

Get all files in a Google Drive (or folder if specified).

Parameters
  • page_size

  • limit

  • credentials – GSuite credentials object.

  • folder_id – GDrive folder to search in (optional)

Returns

Pandas DataFrame of files in a Google Drive.

classmethod get_file_revisions(file_id, credentials)[source]
Parameters
  • file_id

  • credentials

Returns

classmethod upload_files(folder_id, upload_filepaths, credentials, upload_filenames=False, upload_from_memory=False)[source]

Uploads files to a folder on Google Drive.

Parameters
  • folder_id – ID of folder to upload files into.

  • credentials – GSuite credentials object.

  • upload_filepaths – Filepaths for files to upload.

  • upload_filenames – Filenames for files, must match length of filepaths (optional). Otherwise uses filepath names.

Returns

Confirmation of files being uploaded.