gdrive-access is a simplified set of Python functions for navigating Google Drive folders and uploading/downloading files, built on PyDrive. To get set up, you will need to install gdrive-access and run the "setup credentials" script (python -m gdrive_access.setup_credentials --dir CREDENTIALS_DIR
) to give it permission to access your Google Drive through the Google Drive web API.
gdrive-access should work on any version of Python 3 but has only been tested on Python 3.9. It is recommended to install it in a virtual environment.
To install the latest
pip install git+https://github.com/theunissenlab/[email protected]
Run the following script and follow the instructions carefully. Optionally, specify a CREDENTIALS_DIR where gdrive-access will put credential files (defaults to current working directory). It will create files settings.yaml
and credentials.json
in that directory. You will also create a file in it called client_secrets.json
during the setup process.
setup_gdrive_credentials --dir CREDENTIALS_DIR
from gdrive_access import GDriveCommands
Alternatively, specify the custom path to CREDENTIALS_DIR/settings.yaml
if you did not use the default during setup.
g = GDriveCommands("settings.yaml")
For these methods, if the first argument is not an instance of pydrive2.files.GoogleDriveFile
, will assume the path is relative to the root directory.
Get a pointer to a specific folder or path.
g.find(GDRIVE_DIRECTORY, *path_elements) # -> GDRIVE_FILE/GDRIVE_DIRECTORY
g.find(*path_elements) # -> GDRIVE_FILE/GDRIVE_DIRECTORY
List the contents of a folder.
g.ls(GDRIVE_DIRECTORY, *path_elements) # -> list of GDRIVE_FILEs
g.ls(*path_elements) # -> list of GDRIVE_FILEs
Check if a given path exists
g.exists(GDRIVE_DIRECTORY, *path_elements) # -> bool
g.exists(*path_elements) # -> bool
g.download_file(GDRIVE_FILE, local_path, overwrite=g.Overwrite.NEVER)
g.download_files([GDRIVE_FILE1, GDRIVE_FILE2, ...], local_folder_path, overwrite=g.Overwrite.NEVER)
g.download_folder(GDRIVE_DIRECTORY, local_folder_path, overwrite=g.Overwrite.NEVER)
g.create_folder(GDRIVE_DIRECTORY, folder_name) # -> GDRIVE_DIRECTORY
g.upload_file(local_file_path, GDRIVE_DIRECTORY, overwrite=g.Overwrite.ON_MD5_CHECKSUM_CHANGE)
pip uninstall gdrive-access
- Have a way to resolve when multiple files have the same name?