This repository provides a ContentsManager for Jupyter that stores notebook files in Google Cloud Storage.
This is not an officially supported Google product.
- Install pipenv.
- Run
pipenv install
in this folder. - Run
pipenv shell
to activate the virtual Python environment with the necessary dependencies installed.
You must have the GCS Python client library installed. You can install it using the following command:
pip install google-cloud-storage
Additionally, you must have application default credentials set up. Those can be created using the following command:
gcloud auth application-default login
Download the gcs_contents_manager.py
file from this repository,
and then copy it into a directory in your PYTHONPATH.
Add the following lines to your Jupyter config file (e.g. jupyter_notebook_config.py):
from gcs_contents_manager import GCSContentsManager
c.NotebookApp.contents_manager_class = GCSContentsManager
c.GCSContentsManager.bucket_name = '${NOTEBOOK_BUCKET}'
c.GCSContentsManager.bucket_notebooks_path = '${NOTEBOOK_PATH}'
c.GCSContentsManager.project = '${NOTEBOOK_PROJECT}'
For ${NOTEBOOK_BUCKET}
specify the name of the GCS bucket where
you want to store your notebooks, and for ${NOTEBOOK_PATH}
,
specify the name of the directory within that bucket that will be
treated as your root directory by Jupyter.
For ${NOTEBOOK_PROJECT}
specify the name of your GCP project
that you want to use for Jupyter. For most uses this will be the
same project that owns the GCS bucket.