Skip to main content

kaggle-wandb-sync

PyPI version Test License: MIT

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:

  1. Running your notebook with WANDB_MODE=offline (logs saved locally on Kaggle)
  2. Downloading the output via kaggle kernels output
  3. 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   username/my-notebook              # wait for COMPLETE
kaggle-wandb-sync output username/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=offline before import 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

kaggle-wandb-sync output

Download output files from a completed Kaggle kernel.

kaggle-wandb-sync output [KERNEL_ID] [OPTIONS]
Option Default Description
--output-dir, -o ./kaggle_output Directory to save downloaded files.

kaggle-wandb-sync poll

Poll a Kaggle kernel until it reaches COMPLETE, ERROR, or CANCEL.

kaggle-wandb-sync poll [KERNEL_ID] [OPTIONS]
Option Default Description
--interval 30 Seconds between status checks.
--max-attempts 60 Maximum number of status checks before giving up.

kaggle-wandb-sync push

Push a Kaggle Notebook to Kaggle.

kaggle-wandb-sync push [DIRECTORY] [OPTIONS]
Option Default Description
--wait-interval 30 Seconds between status checks when waiting for a running kernel.
--max-wait 20 Maximum number of status checks before giving up on waiting.
--dry-run Show the command without executing it.

kaggle-wandb-sync run

Run the full pipeline: push → poll → output → wandb sync → wait for submission → record LB score.

kaggle-wandb-sync run [DIRECTORY] [OPTIONS]
Option Default Description
--kernel-id, -k Kernel ID (default: read from kernel-metadata.json).
--output-dir, -o ./kaggle_output Directory to save downloaded output.
--poll-interval 30 Seconds between status checks.
--max-attempts 60 Maximum poll attempts.
--skip-push Skip push (re-run output+sync only).
--skip-sync Skip wandb sync (download output only).
--competition-slug Competition slug to auto-record LB score after submission (e.g. march-machine-learning-mania-2026).

kaggle-wandb-sync score

Log Kaggle submission scores to a W&B run.

kaggle-wandb-sync score [RUN_ID] [OPTIONS]
Option Default Description
--project, -p W&B project path (entity/project). Required if RUN_ID is a bare ID.
--score Kaggle public LB score.
--rank Leaderboard rank.
--metric, -m Additional metric (can be repeated, e.g. -m auc=0.95 -m loss=0.3).

kaggle-wandb-sync sync

Sync W&B offline runs found in OUTPUT_DIR to W&B cloud.

kaggle-wandb-sync sync [OUTPUT_DIR] [OPTIONS]

Command notes

Behaviour that is not visible in the option tables above:

  • push waits for any currently running kernel to finish before pushing, which prevents 409 Conflict errors.

  • poll exits with code 1 if the kernel finishes with ERROR or CANCEL. Since v0.1.5 it also downloads the kernel log on those outcomes and prints stdout plus the last 30 stderr lines, so you can diagnose a failure without opening the Kaggle UI.

  • sync finds every offline-run-* directory under the output dir and runs wandb sync on each.

  • score takes a full run URL, an entity/project/id path, or a bare id with --project:

    kaggle-wandb-sync score https://wandb.ai/me/my-proj/runs/abc123 --score 0.127 --rank 200
    

The section above Command notes is generated from the Click definitions by scripts/gen_commands_doc.py and rewritten by CI on every push. Put anything hand-written here, below <!-- commands:end -->, or it will be overwritten.

Known Issues

  • Windows encoding: Prefix commands with PYTHONUTF8=1 if you see encoding errors on Windows.

  • Windows PATH (Microsoft Store Python): If kaggle-wandb-sync: command not found in 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"
    
  • Git Bash path format (fixed in v0.1.2): Git Bash converts paths like C:/Users/... to /c/Users/..., which Python cannot resolve. As of v0.1.2, all path arguments are automatically converted to Windows format.

License

MIT

Metadata

Release files for kaggle-wandb-sync 0.1.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kaggle-wandb-sync 0.1.11
File Size Uploaded
kaggle_wandb_sync-0.1.11.tar.gz 14.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kaggle-wandb-sync 0.1.11
File Interpreter ABI Platform
kaggle_wandb_sync-0.1.11-py3-none-any.whl Python 3 none any Details

Total release size: 30.9 kB

Release files / kaggle_wandb_sync-0.1.11.tar.gz

Download URL kaggle_wandb_sync-0.1.11.tar.gz
Size 14.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c3b6d83896e9a138f925ab04d48710762c066d12cc4f06a86af145fae1a8be6b
BLAKE2b-256 checksum
How to use checksums
832a0c43e0cb279341922288f9b56f2d07b516bac69c91ed33085e69dad462f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.

Transparency log

Release files / kaggle_wandb_sync-0.1.11-py3-none-any.whl

Download URL kaggle_wandb_sync-0.1.11-py3-none-any.whl
Size 16.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
59eba22255964b1f08651b0b525a1cc7540db722603aa058f3be6bfaf1cf1a81
BLAKE2b-256 checksum
How to use checksums
bbf506a8ecd71cfe2ef86cf8871334fcd1ded36292a9e33672bc8924b8a1569f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.11 This release

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page