Execute code on remote Kaggle Jupyter kernels from your terminal
Project description
kgz
Execute code on Kaggle GPU & TPU kernels from your terminal.
Free GPUs. Free TPUs. No browser needed.
Guide · Agent Guide · GitHub
Why?
Kaggle gives you free GPUs (2x T4, 30h/week) and free TPUs (v3-8, 20h/week). But you're stuck in a browser notebook. kgz lets you drive Kaggle from your terminal, scripts, or AI agents.
from kgz import Kernel
k = Kernel("https://kkb-production.jupyter-proxy.kaggle.net/k/.../proxy")
result = k.execute("import jax; print(jax.devices())")
# [CudaDevice(id=0), CudaDevice(id=1)]
Install
pip install kgz
Single dependency: websocket-client.
Getting Your URL
- Open a notebook on kaggle.com/code
- Enable GPU or TPU in Settings
- Copy the URL from your browser bar
- Pass it to kgz
Features
Execute with Structured Output
result = k.execute("print('hello'); 2+2", stream=False)
result.success # True
result.stdout # "hello\n"
result.return_value # "4"
result.elapsed_seconds # 0.1
GPU & TPU Support
k.is_tpu() # True if TPU kernel
k.device_info() # Full device details
k.tpu_type() # "TPU v3-8" or "Tesla T4"
k.resources() # GPU util%, VRAM, CPU%, RAM
Health Dashboard
k.health_check()
# Kernel: busy
# Backend: gpu (2 devices)
# GPU 0: 85% util, 12000/15360 MB
# GPU 1: 82% util, 11500/15360 MB
# CPU: 17%
# RAM: 8.6/33.7 GB
# Train: step 1234/5000 | loss 2.31 | 56,000 tok/s
# ETA: ~35m
# Quota: 27.9h remaining (GPU)
Quota Tracking (30h/week GPU, 20h/week TPU)
k.start_quota_tracking()
# ... train for hours ...
k.stop_quota_tracking()
k.quota_summary()
# GPU: 4.2h used / 30h quota (25.8h remaining)
# Session: 7.8h before expiry
Output Caching (98x speedup)
result = k.execute_cached("pip install -q jax flax")
# First: 5s (remote), Second: 0.001s (local cache)
Pipeline (Run-Once)
results = k.pipeline([
("Install", "pip install -q jax flax"),
("Check GPU", "import jax; print(jax.devices())"),
("Train", "train(steps=5000)"),
], notify_url="https://hooks.slack.com/...", use_cache=True)
# Tracks quota, caches setup, notifies Slack on complete/fail
Notebook Import & Export
results = k.run_notebook("training.ipynb") # Run existing .ipynb
k.to_notebook("output.ipynb") # Export history as .ipynb
Kaggle Datasets
k.list_datasets() # Show mounted datasets
k.attach_dataset("openai/gsm8k") # Check availability
File Operations
from kgz import upload_file, download_file, FileSync
upload_file(url, "model.py", "model.py")
k.download_model("/kaggle/working/model.pkl", "./model.pkl")
sync = FileSync(url, "./src", "/kaggle/working/src")
sync.start() # Background watch — auto-upload on change
Secrets (excluded from history & export)
k.set_env(WANDB_API_KEY="...", HF_TOKEN="...")
Environment Snapshot
k.snapshot_env() # pip freeze → local file
k.restore_env() # Restore packages (after kernel restart)
Budget Alerts
k.set_budget(max_hours=8, notify_url="https://hooks.slack.com/...")
# Alert at 80%, interrupt at limit
Sessions & Profiles
k.save_session() # Save for later
k = Kernel.resume("my-session") # Resume
k.save_profile("gpu-training") # Save config
k = Kernel.from_profile("gpu-training") # Reuse
Notifications
k.execute_notify(code, notify_url="https://hooks.slack.com/...", label="Training")
Parallel Execution
k1, k2 = Kernel(url1), Kernel(url2)
results = Kernel.parallel_execute([k1, k2], "import jax; print(jax.devices())")
Persistent Connection
WebSocket reused across calls — no reconnect overhead:
for i in range(100):
k.execute(f"step({i})", stream=False) # ~100ms each, not 500ms
Error Handling
from kgz import KernelError
try:
k.execute("1/0", raise_on_error=True, stream=False)
except KernelError as e:
print(e.result.traceback)
CLI
kgz run URL "code" # Execute code
kgz exec URL -f script.py # Execute file
kgz status URL # idle/busy
kgz interrupt URL # Ctrl-C
kgz wait URL # Block until idle
kgz upload URL file [remote] # Upload
kgz download URL remote [local] # Download
kgz ls URL [path] # List files
kgz snapshot URL # Variable inspection
kgz resources URL # GPU/TPU/CPU usage
kgz sync URL local_dir # Watch & sync
kgz notebook URL -f cells.txt # Run notebook cells
kgz sessions # List saved sessions
Kaggle Limits
| Resource | Weekly Limit | Session Max |
|---|---|---|
| GPU (T4) | 30 hours | 12 hours |
| TPU (v3-8) | 20 hours | 9 hours |
Use k.quota_summary() to check remaining time.
Documentation
- Usage Guide — Complete feature walkthrough
- Agent Guide — Patterns for AI coding agents
Pair with tpuz
pip install kgz # Kaggle free GPUs/TPUs
pip install tpuz # GCP TPU/GPU pods
Claude Code
mkdir -p ~/.claude/skills/kgz-guide
cp SKILL.md ~/.claude/skills/kgz-guide/skill.md
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 kgz-0.1.4.tar.gz.
File metadata
- Download URL: kgz-0.1.4.tar.gz
- Upload date:
- Size: 34.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b49e85ca4fa43cf6813b9a1ea1744108525bcd58467dbbe45048da62ba752163
|
|
| MD5 |
758b9d27865ee9741edc5352b76153b3
|
|
| BLAKE2b-256 |
666a0acc629049160b641bc009f8d353bff6af15b8e81fd7e25485d7975737c0
|
Provenance
The following attestation bundles were made for kgz-0.1.4.tar.gz:
Publisher:
publish.yaml on mlnomadpy/kgz
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kgz-0.1.4.tar.gz -
Subject digest:
b49e85ca4fa43cf6813b9a1ea1744108525bcd58467dbbe45048da62ba752163 - Sigstore transparency entry: 1247896497
- Sigstore integration time:
-
Permalink:
mlnomadpy/kgz@91bae3c418149f1124bf5ebadaa1926b62806791 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/mlnomadpy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@91bae3c418149f1124bf5ebadaa1926b62806791 -
Trigger Event:
push
-
Statement type:
File details
Details for the file kgz-0.1.4-py3-none-any.whl.
File metadata
- Download URL: kgz-0.1.4-py3-none-any.whl
- Upload date:
- Size: 24.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
216892105e13a058894791a07ec9195a827c1603d24605dfd4dddad501fedfc1
|
|
| MD5 |
2fad7bbb628b25156a4ffb8f117624d2
|
|
| BLAKE2b-256 |
4746a67f36e3e04f1117555e7a32ddd2385f3817f7aed57606e60b753d08a032
|
Provenance
The following attestation bundles were made for kgz-0.1.4-py3-none-any.whl:
Publisher:
publish.yaml on mlnomadpy/kgz
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kgz-0.1.4-py3-none-any.whl -
Subject digest:
216892105e13a058894791a07ec9195a827c1603d24605dfd4dddad501fedfc1 - Sigstore transparency entry: 1247896578
- Sigstore integration time:
-
Permalink:
mlnomadpy/kgz@91bae3c418149f1124bf5ebadaa1926b62806791 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/mlnomadpy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@91bae3c418149f1124bf5ebadaa1926b62806791 -
Trigger Event:
push
-
Statement type: