Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions scripts/notebook-setup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Notebook Setup Helper (`notebook_setup.py`)

`notebook_setup.py` provides a standard-library bootstrap utility for notebooks in `python-docs-samples` that depend on sibling Python modules and `requirements.txt` files when opened standalone in Google Colab or Colab Enterprise.

## Usage in a Notebook

```python
# @title Download sample files and install packages (~30 seconds)
from pathlib import Path
import sys
import tempfile
import urllib.request

BRANCH = "main"
SETUP_PATH = Path(tempfile.gettempdir()) / "notebook_setup.py"
for parent in (Path.cwd(), *Path.cwd().parents):
candidate = parent / "scripts/notebook-setup/notebook_setup.py"
if candidate.is_file():
SETUP_PATH = candidate
break
else:
if not SETUP_PATH.is_file():
url = (
"https://raw.githubusercontent.com/GoogleCloudPlatform/"
f"python-docs-samples/{BRANCH}/scripts/notebook-setup/notebook_setup.py"
)
with urllib.request.urlopen(url, timeout=30) as response:
SETUP_PATH.write_bytes(response.read())

setup_dir = str(SETUP_PATH.parent.resolve())
if setup_dir not in sys.path:
sys.path.insert(0, setup_dir)
import notebook_setup

notebook_setup.bootstrap("people-and-planet-ai/weather-forecasting", branch=BRANCH)
```
13 changes: 13 additions & 0 deletions scripts/notebook-setup/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Loading
Loading