Google Drive¶
DriveUtility¶
-
class
gwrappy.drive.
DriveUtility
(json_credentials_path, client_id, **kwargs)[source]¶ Initializes object for interacting with Bigquery API.
Parameters: - client_secret_path – File path for client secret JSON file. Only required if credentials are invalid or unavailable.
- json_credentials_path – File path for automatically generated credentials.
- client_id – Credentials are stored as a key-value pair per client_id to facilitate multiple clients using the same credentials file. For simplicity, using one’s email address is sufficient.
- max_retries (integer) – Argument specified with each API call to natively handle retryable errors.
- chunksize (integer) – Upload/Download chunk size
-
get_account_info
(fields=None)[source]¶ Abstraction of about().get() method. [https://developers.google.com/drive/v3/reference/about/get]
Parameters: fields (list or ", " delimited string) – Available properties can be found here: https://developers.google.com/drive/v3/reference/about Returns: Dictionary object representation of About resource.
-
list_files
(max_results=None, **kwargs)[source]¶ Abstraction of files().list() method with inbuilt iteration functionality. [https://developers.google.com/drive/v3/reference/files/list]
Parameters: - max_results (integer) – If None, all results are iterated over and returned.
- fields – Available properties can be found here: https://developers.google.com/drive/v3/reference/about
- spaces – A comma-separated list of spaces to query within the corpus. Supported values are ‘drive’, ‘appDataFolder’ and ‘photos’.
- q – A query for filtering the file results. Reference here: https://developers.google.com/drive/v3/web/search-parameters
Returns: List of dictionary objects representing file resources.
-
get_file
(file_id, fields=None)[source]¶ Get file metadata.
Parameters: - file_id (string) – Unique file id. Check on UI or by list_files().
- fields (list or ", " delimited string) – Available properties can be found here: https://developers.google.com/drive/v3/reference/about
Returns: Dictionary object representing file resource.
-
download_file
(file_id, write_path, page_num=None, output_type=None)[source]¶ Downloads object.
Parameters: - file_id (string) – Unique file id. Check on UI or by list_files().
- write_path (string) – Local path to write object to.
- page_num (integer) – Only applicable to Google Sheets. Check gid param in URL.
- output_type (string. 'list' or 'dataframe') – Only applicable to Google Sheets. Can be directly downloaded as list or Pandas dataframe.
Returns: If Google Sheet and output_type specified: result in selected type, DriveResponse object. Else DriveResponse object.
Raises: HttpError if non-retryable errors are encountered.
-
upload_file
(read_path, overwrite_existing=True, **kwargs)[source]¶ Creates file if it doesn’t exist, updates if it does.
Parameters: - read_path (string) – Local path of object to upload.
- overwrite_existing (boolean) – Safety flag, would raise ValueError if object exists and overwrite_existing=False
- kwargs – Key-Value pairs of Request Body params. Reference here: https://developers.google.com/drive/v3/reference/files
Returns: DriveResponse object.