Exporting to Google Drive from the Sandbox
Keywords package; google
Background
Google Drive API enables developers to integrate Google Drive functionality into applications, offering access to file storage, sharing, and synchronization capabilities. It allows users to manage files, folders, and permissions programmatically, facilitating seamless integration of cloud storage features into various software solutions. The API supports multiple programming languages and provides robust documentation, making it versatile for a wide range of applications from document management to collaborative platforms. More information can be found here.
To connect to the Google Drive API from the Sandbox using a service account, a service account
is created in the Google Cloud Console. Users then need to download its JSON key file, and configure permissions on both Google Drive and the service account. This approach bypasses user authentication and allows server-to-server interactions, making it suitable for automated tasks or applications where user interaction is not required. The service account JSON key is securely stored and used by
Python code within Jupyter notebooks to authenticate and authorize API requests, enabling seamless integration of Google Drive functionalities directly into data science workflows without user intervention.
Detailed instructions on integrating Google Drive are documented in the DE Africa user guide.
Security considerations: Users should take care to ensure the security of credentials uploaded into the Sandbox, including by ensuring they are not incidentally included in uploads to public repositories like GitHub.
Description
This notebook provides a brief introduction to accessing and using Digital Earth Africa’s sandbox with Google Drive:
The packages to load up
How to use the list files in the google drive
How to upload file files in the google drive
Getting started
To use this notebook, make sure to follow these steps here before proceeding to the next cell.
Load packages
Import Python packages that are used for the analysis.
[1]:
from deafrica_tools.externaldrive import list_gdrive, upload_to_gdrive
List Files in Google Drive
list_gdrive
function list the files and folder within the service account drive.
[2]:
list_gdrive()
Files:
Animated_timeseries.ipynb (19oBKPC8BKN77d45STpk1xAmA8_2gxYLO)
deafricaout (1Cn3e0m8T0OPjZ4dZOnoeXBiGrNiuLo0Y)
Upload to Google Drive
upload_to_gdrive
function uploads the files to google drive. it takes two parameter
file_path
: path to the file to upload
[3]:
upload_to_gdrive(file_path='Animated_timeseries.ipynb')
File Uploaded successful
Additional information
License: The code in this notebook is licensed under the Apache License, Version 2.0. Digital Earth Africa data is licensed under the Creative Commons by Attribution 4.0 license.
Contact: If you need assistance, please post a question on the Open Data Cube Slack channel or on the GIS Stack Exchange using the open-data-cube
tag (you can view previously asked questions here). If you would like to report an issue with this notebook, you can file one on
Github.
Compatible datacube version:
[4]:
import datacube
print(datacube.__version__)
1.8.15
Last Tested:
[5]:
from datetime import datetime
datetime.today().strftime('%Y-%m-%d')
[5]:
'2024-07-25'