A CLI tool to sync W&B offline runs from Kaggle Notebooks via GitHub Actions
Project description
kaggle-wandb-sync
A CLI tool to sync Weights & Biases offline runs from Kaggle Notebooks to W&B cloud — fully automated via GitHub Actions.
Why?
Kaggle Notebooks run in an isolated environment with internet access disabled for competition submissions. This means you can't push W&B metrics in real time. kaggle-wandb-sync solves this by:
- Running your notebook with
WANDB_MODE=offline(logs saved locally on Kaggle) - Downloading the output via
kaggle kernels output - Syncing the offline runs to W&B cloud with
wandb sync
Installation
pip install kaggle-wandb-sync
Prerequisites: Kaggle API credentials (~/.kaggle/kaggle.json) and a W&B API key (WANDB_API_KEY env var, or run wandb login once to save credentials to ~/.netrc).
Quick Start
All-in-one command
# Set your W&B API key
export WANDB_API_KEY=your_api_key
# Push notebook, wait for completion, download output, sync to W&B
kaggle-wandb-sync run my-notebook/
Step by step
kaggle-wandb-sync push my-notebook/ # push (with 409 protection)
kaggle-wandb-sync poll yasunorim/my-notebook # wait for COMPLETE
kaggle-wandb-sync output yasunorim/my-notebook # download output
kaggle-wandb-sync sync ./kaggle_output # wandb sync
Notebook Setup
Add these lines before importing wandb in your Kaggle Notebook:
import os
os.environ['WANDB_MODE'] = 'offline' # must be set before import
os.environ['WANDB_PROJECT'] = 'my-project'
import wandb
wandb.init()
# ... your training code ...
wandb.log({"loss": 0.1, "accuracy": 0.95})
wandb.finish()
Important: Set
WANDB_MODE=offlinebeforeimport wandb, not after.
GitHub Actions Integration
Add this workflow to your Kaggle repo (.github/workflows/kaggle-wandb-sync.yml):
name: Kaggle W&B Sync
on:
workflow_dispatch:
inputs:
notebook_dir:
description: "Notebook directory (e.g. my-competition)"
required: true
kernel_id:
description: "Kernel ID (e.g. username/my-competition-baseline)"
required: true
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install kaggle-wandb-sync
run: pip install kaggle-wandb-sync
- name: Set up Kaggle credentials
run: |
mkdir -p ~/.kaggle
echo '${{ secrets.KAGGLE_API_TOKEN }}' > ~/.kaggle/kaggle.json
chmod 600 ~/.kaggle/kaggle.json
- name: Run pipeline
env:
WANDB_API_KEY: ${{ secrets.WANDB_API_KEY }}
run: |
kaggle-wandb-sync run ${{ inputs.notebook_dir }} \
--kernel-id ${{ inputs.kernel_id }}
Required secrets: KAGGLE_API_TOKEN (JSON content of ~/.kaggle/kaggle.json) and WANDB_API_KEY.
Commands
run — Full pipeline (recommended)
kaggle-wandb-sync run [DIRECTORY] [OPTIONS]
| Option | Default | Description |
|---|---|---|
--kernel-id, -k |
from metadata | Kernel ID (username/slug) |
--output-dir, -o |
./kaggle_output |
Directory for downloaded files |
--poll-interval |
30 |
Seconds between status checks |
--max-attempts |
60 |
Max poll attempts (30min total) |
--skip-push |
off | Skip push step (use when notebook has already finished running) |
--skip-sync |
off | Download output only, skip W&B sync |
push — Push notebook
kaggle-wandb-sync push [DIRECTORY] [OPTIONS]
Waits for any currently running kernel to finish before pushing (prevents 409 Conflict errors).
poll — Wait for completion
kaggle-wandb-sync poll KERNEL_ID [--interval 30] [--max-attempts 60]
Exits with code 1 if the kernel finishes with ERROR or CANCEL.
output — Download output
kaggle-wandb-sync output KERNEL_ID [--output-dir ./kaggle_output]
sync — Sync to W&B
kaggle-wandb-sync sync [OUTPUT_DIR]
Finds all offline-run-* directories and runs wandb sync on each.
Known Issues
-
Windows encoding: Prefix commands with
PYTHONUTF8=1if you see encoding errors on Windows. -
Windows PATH (Microsoft Store Python): If
kaggle-wandb-sync: command not foundin Git Bash, add the Scripts directory to your PATH:# Add to ~/.bashrc export PATH="$PATH:/c/Users/<your-username>/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0/LocalCache/local-packages/Python312/Scripts"
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kaggle_wandb_sync-0.1.1.tar.gz.
File metadata
- Download URL: kaggle_wandb_sync-0.1.1.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b174dea4c71d2e81cd397ed9c937a1bb9b70ccf834c34f0b3b756b91c4c834f
|
|
| MD5 |
ffe44f4dbda5005a2e28ddb0704d042f
|
|
| BLAKE2b-256 |
c384ff90a1b51fe1054e42de1a656cf08f0bee344a047743c116aa3093471a89
|
Provenance
The following attestation bundles were made for kaggle_wandb_sync-0.1.1.tar.gz:
Publisher:
publish.yml on yasumorishima/kaggle-wandb-sync
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kaggle_wandb_sync-0.1.1.tar.gz -
Subject digest:
3b174dea4c71d2e81cd397ed9c937a1bb9b70ccf834c34f0b3b756b91c4c834f - Sigstore transparency entry: 975969376
- Sigstore integration time:
-
Permalink:
yasumorishima/kaggle-wandb-sync@99ff00ca099c61dde827ce307b623169a7bc3905 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/yasumorishima
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@99ff00ca099c61dde827ce307b623169a7bc3905 -
Trigger Event:
release
-
Statement type:
File details
Details for the file kaggle_wandb_sync-0.1.1-py3-none-any.whl.
File metadata
- Download URL: kaggle_wandb_sync-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b849a133052f06cf5d73d8aa0cdc355316cd408eaeb3a37c3445b2de0f14aeb
|
|
| MD5 |
eb7a8e8b38264fece42f1c571f637346
|
|
| BLAKE2b-256 |
d5afae87fb78869568f8591e12c9d3d4e14be0b9012a1d497dbf6725eb501cc7
|
Provenance
The following attestation bundles were made for kaggle_wandb_sync-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on yasumorishima/kaggle-wandb-sync
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kaggle_wandb_sync-0.1.1-py3-none-any.whl -
Subject digest:
6b849a133052f06cf5d73d8aa0cdc355316cd408eaeb3a37c3445b2de0f14aeb - Sigstore transparency entry: 975969384
- Sigstore integration time:
-
Permalink:
yasumorishima/kaggle-wandb-sync@99ff00ca099c61dde827ce307b623169a7bc3905 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/yasumorishima
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@99ff00ca099c61dde827ce307b623169a7bc3905 -
Trigger Event:
release
-
Statement type: