This is a library to write simple Google Drive management/backup tools using Python.
After quickly setting up the environment you can run the google drive commander like this:
# List files in the root directory
bin/gdrive ls /
# Download a file
bin/gdrive scp drive:/test.pdf ~/test.pdf
# Upload a file
bin/gdrive scp ~/test.pdf drive:/test.pdf
# Download a sheet as CSV
bin/gdrive csv-download "/My Spreadheet" "Sheet 1" ~/output.csv
# Upload a CSV into a spreadsheet
bin/gdrive csv-upload "/My Spreadsheet" "Upload" ~/upload.csv
You need to only do two small things to be able to access the Google Drive API. You need to set up the python environment with the relevant libraries and set up permissions in the Drive itself. Below is information on how to do both of these things.
You'll need to run the following commands to setup the virtual environment and download the packages:
python3 -m venv .google-drive-venv
source .google-drive-venv/bin/activate
pip3 install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib oauth2client mypy pylint
To use the Google Drive API you need to do step 1 and step 2 as outlined in these docs (this needs to be done only once): https://developers.google.com/drive/api/v3/quickstart/python
You can see your live projects here: https://console.cloud.google.com/
Then you'll need to move the credentials.json
and token.json
files either to where you are running the gdrive binary from or pass the location in using the arguments gdrive --token ~/token.json --creds ~/creds.json
.
Drive API Docs
- https://developers.google.com/resources/api-libraries/documentation/drive/v3/python/latest/drive_v3.files.html
- https://developers.google.com/drive/api/v3/manage-downloads
Sheets API Docs