Google Cloud Jupyter Config
google-cloud-jupyter-config is a Python library that provides utilities for Jupyter environments to retrieve configuration information directly from the Google Cloud SDK (gcloud CLI) and Google Cloud metadata server. It's designed to be a reusable helper for other Jupyter extensions and applications, enabling seamless access to details like project IDs and authentication tokens. The current version is 0.0.12, with releases being infrequent and often tied to the broader 'jupyter-extensions' project.
Common errors
-
ModuleNotFoundError: No module named 'google_cloud_jupyter_config'
cause The `google-cloud-jupyter-config` package is not installed in the Python environment where your Jupyter kernel is running.fixRun `pip install google-cloud-jupyter-config` in your environment. If using a virtual environment, ensure it's activated, or if on a JupyterLab instance, install it into the appropriate kernel environment. -
Could not retrieve Google Cloud Project ID. Is gcloud SDK configured or GCLOUD_PROJECT env var set?
cause The library could not determine the active Google Cloud project ID from environment variables, `gcloud` CLI configuration, or metadata server. This often happens if `gcloud` is not initialized or authenticated.fixInitialize the Google Cloud SDK by running `gcloud init`. Ensure you are authenticated with `gcloud auth login` or `gcloud auth application-default login`, and a default project is set or `GCLOUD_PROJECT` environment variable is defined. -
403 Forbidden: The caller does not have permission
cause When using `google-cloud-jupyter-config` to retrieve authentication tokens or project details, this error indicates the underlying Google Cloud identity (user or service account) lacks the necessary IAM permissions to access a specific resource or perform an action.fixVerify that the service account or user associated with your Jupyter environment has the required IAM roles and permissions for the Google Cloud project and resources you are trying to access. Use the Google Cloud Console's IAM & Admin section to review and adjust permissions.
Warnings
- gotcha Prior to version 0.0.12, Jupyter sessions integrated with this library could experience authentication token expiration during long-running connections, leading to interrupted workflows.
- gotcha The library heavily relies on the Google Cloud SDK (gcloud CLI) being installed and correctly configured and authenticated on the system where Jupyter is running. Without it, many utility functions may return `None` or fail.
- deprecated The root `google-cloud` PyPI package is deprecated. Users should install product-specific client libraries like `google-cloud-jupyter-config` instead of the umbrella package.
Install
-
pip install google-cloud-jupyter-config
Imports
- project
from google_cloud_jupyter_config import project
- token
from google_cloud_jupyter_config import token
- settings
from google_cloud_jupyter_config import settings
Quickstart
import os
from google_cloud_jupyter_config import project
from google_cloud_jupyter_config import token
# Ensure gcloud CLI is configured, or environment variables are set
# For example, by running 'gcloud auth application-default login' or setting GCLOUD_PROJECT
project_id = project.get_project_id()
if project_id:
print(f"Google Cloud Project ID: {project_id}")
else:
print("Could not retrieve Google Cloud Project ID. Is gcloud SDK configured or GCLOUD_PROJECT env var set?")
access_token = token.get_access_token()
if access_token:
print(f"Google Cloud Access Token (first 10 chars): {access_token[:10]}...")
else:
print("Could not retrieve Google Cloud Access Token. Is gcloud SDK authenticated?")