Skip to content

shepsci/kaggle-skill / skills/kaggle

kaggle

Flagged

Unified Kaggle skill. Use when the user explicitly mentions Kaggle, kaggle.com, a Kaggle URL, Kaggle competitions, Kaggle datasets/models/notebooks, Kaggle forums/discussions/writeups, Kaggle benchmarks, hackathons hosted on Kaggle, Kaggle badges, or Kaggle account setup. Do not use for generic ML, GPU/TPU, notebook, dataset, benchmark, or data-science tasks unless the user clearly ties them to Kaggle.

FileKindSize
SKILL.mdskill md10.3 KB
modules/README.mdmarkdown2.3 KB
modules/badges/README.mdmarkdown1.6 KB
modules/badges/references/badge-catalog.mdmarkdown6.6 KB
modules/badges/scripts/badge_registry.pyscript8.5 KB
modules/badges/scripts/badge_tracker.pyscript4.1 KB
modules/badges/scripts/orchestrator.pyscript5.3 KB
modules/badges/scripts/phase_1_instant_api.pyscript24.0 KB
modules/badges/scripts/phase_2_competition.pyscript13.5 KB
modules/badges/scripts/phase_3_pipeline.pyscript11.7 KB
modules/badges/scripts/phase_4_browser.pyscript2.2 KB
modules/badges/scripts/phase_5_streaks.pyscript5.6 KB
modules/badges/scripts/templates/README_dataset.mdmarkdown573 B
modules/badges/scripts/templates/dataset-metadata.jsonconfig871 B
modules/badges/scripts/templates/kernel-metadata.jsonconfig412 B
modules/badges/scripts/templates/model-instance-metadata.jsonconfig253 B
modules/badges/scripts/templates/model-metadata.jsonconfig355 B
modules/badges/scripts/templates/python_notebook.ipynbother1.3 KB
modules/badges/scripts/templates/r_notebook.ipynbother1.1 KB
modules/badges/scripts/templates/submission_titanic.csvother2.8 KB
modules/badges/scripts/templates/utility_script.pyscript802 B
modules/badges/scripts/utils.pyscript3.9 KB
modules/benchmarks/README.mdmarkdown1.2 KB
modules/benchmarks/references/benchmark-endpoints.mdmarkdown1.6 KB
modules/benchmarks/references/benchmarks-cli.mdmarkdown4.4 KB
modules/competitions/README.mdmarkdown5.8 KB
modules/competitions/hackathons/README.mdmarkdown2.9 KB
modules/competitions/hackathons/references/episode-endpoints.mdmarkdown2.2 KB
modules/competitions/hackathons/references/hackathon-endpoints.mdmarkdown4.6 KB
modules/competitions/hackathons/scripts/fetch_writeup.pyexecutablescript10.5 KB
modules/competitions/hackathons/scripts/hackathon_overview.pyexecutablescript1.5 KB
modules/competitions/hackathons/scripts/list_writeups.pyexecutablescript9.9 KB
modules/competitions/references/competition-categories.mdmarkdown2.1 KB
modules/competitions/references/competition-operations.mdmarkdown5.7 KB
modules/competitions/references/competition-overview.mdmarkdown3.9 KB
modules/competitions/references/competition-research.mdmarkdown3.0 KB
modules/competitions/scripts/competition_brief.pyscript5.4 KB
modules/competitions/scripts/competition_details.pyscript8.2 KB
modules/competitions/scripts/competition_download.pyscript5.1 KB
modules/competitions/scripts/competition_episodes.pyscript9.2 KB
modules/competitions/scripts/competition_leaderboard.pyscript12.3 KB
modules/competitions/scripts/competition_ledger.pyscript3.3 KB
modules/competitions/scripts/competition_pages.pyexecutablescript1.7 KB
modules/competitions/scripts/competition_status.pyscript9.0 KB
modules/competitions/scripts/competition_submit.pyscript8.9 KB
modules/competitions/scripts/competition_validate.pyscript14.2 KB
modules/competitions/scripts/competition_watch.pyscript5.9 KB
modules/competitions/scripts/list_competitions.pyscript13.3 KB
modules/datasets/README.mdmarkdown2.1 KB
modules/datasets/references/kagglehub-datasets.mdmarkdown2.6 KB
modules/datasets/scripts/dataset_download.pyscript4.1 KB
modules/datasets/scripts/dataset_publish.pyscript5.5 KB
modules/discussions/README.mdmarkdown2.1 KB
modules/discussions/references/writeups.mdmarkdown5.8 KB
modules/discussions/scripts/forums.pyscript22.0 KB
modules/discussions/scripts/leaderboard_writeups.pyscript24.8 KB
modules/models/README.mdmarkdown2.6 KB
modules/models/references/kagglehub-models.mdmarkdown1.7 KB
modules/models/scripts/model_download.pyscript4.5 KB
modules/models/scripts/model_publish.pyscript8.7 KB
modules/notebooks/README.mdmarkdown2.6 KB
modules/notebooks/scripts/notebook_push.pyscript5.7 KB
modules/notebooks/scripts/notebook_run.pyscript2.8 KB
modules/notebooks/scripts/notebook_wait.pyscript3.7 KB
modules/references/README.mdmarkdown454 B
modules/references/cli-reference.mdmarkdown13.4 KB
modules/references/kaggle-knowledge.mdmarkdown7.6 KB
modules/references/mcp-reference.mdmarkdown18.9 KB
modules/setup/README.mdmarkdown3.0 KB
modules/setup/references/kaggle-setup.mdmarkdown6.7 KB
modules/setup/scripts/check_all_credentials.pyscript5.7 KB
modules/setup/scripts/doctor.pyscript10.2 KB
modules/setup/scripts/save_credentials.pyscript3.9 KB
scripts/kaggle_skill.pyscript11.5 KB
shared/__init__.pyscript0 B
shared/competition.pyscript20.0 KB
shared/credentials.pyscript9.6 KB
shared/hub.pyscript2.9 KB
shared/kaggle_cli.pyscript20.7 KB
shared/ledger.pyscript3.6 KB
shared/mcp_client.pyscript11.6 KB
shared/net.pyscript6.9 KB
shared/notebook.pyscript4.4 KB
shared/preflight.pyscript5.1 KB
shared/safe_extract.pyscript2.7 KB
shared/script.pyscript11.2 KB
shared/text.pyscript10.5 KB
shared/untrusted.pyscript7.6 KB

modules/badges/scripts/phase_2_competition.py

View on GitHub
"""Phase 2: Competition badges (7 badges).

Earns badges by submitting to various competition types:
  - Competitor, Getting Started Competitor, Playground Competitor
  - Community Competitor, Code Submitter
  - Notebook Modeler, Competition Modeler

Uses pre-built submission_titanic.csv and finds active competitions via CLI.
"""

from __future__ import annotations

import json
from pathlib import Path
from typing import Optional

from badge_tracker import set_status, should_attempt
from utils import (
    TEMPLATES_DIR,
    make_temp_dir,
    resource_name,
    run_kaggle_cli,
    show_cli_output,
)

from shared.safe_extract import safe_extract  # utils puts the skill root on sys.path


def _safe_extract(zf_path: Path, dest: Path) -> None:
    """Extract ``zf_path`` into ``dest`` with the shared zip-slip check.

    Raises ValueError, and writes nothing, if a member would land outside
    ``dest`` or is a symlink. Kaggle archives are untrusted input.
    """
    safe_extract(zf_path, dest)


def _parse_competition_slugs(stdout: str) -> list[str]:
    """Competition slugs from `kaggle competitions list --format json` output.

    The CLI can print a "Next Page Token" line around the JSON, and prints
    "No competitions found" when the list is empty, so only the JSON array is
    read. Anything else yields no slugs.
    """
    start, end = stdout.find("["), stdout.rfind("]")
    if start < 0 or end < start:
        return []
    try:
        rows = json.loads(stdout[start : end + 1])
    except ValueError:
        return []
    slugs = []
    for row in rows if isinstance(rows, list) else []:
        ref = str(row.get("ref", "")) if isinstance(row, dict) else ""
        slug = ref.rstrip("/").split("/")[-1]
        if slug:
            slugs.append(slug)
    return slugs


def _find_competition(*filter_args: str) -> Optional[str]:
    """First competition the CLI lists for the given filter, or None."""
    result = run_kaggle_cli(
        ["competitions", "list", *filter_args, "--sort-by", "latestDeadline", "--format", "json"],
        check=False,
    )
    if result.returncode != 0:
        return None
    slugs = _parse_competition_slugs(result.stdout)
    return slugs[0] if slugs else None


def _find_competition_by_category(category: str) -> Optional[str]:
    """Find an active competition by category (playground, research, ...)."""
    return _find_competition("--category", category)


def _submit_titanic(username: str) -> bool:
    """Submit to Titanic (Getting Started) competition.

    Earns: Competitor, Getting Started Competitor.
    """
    badge_ids = ["competitor", "getting_started_competitor"]
    actionable = [b for b in badge_ids if should_attempt(b)]
    if not actionable:
        return True

    for bid in actionable:
        set_status(bid, "attempting")

    try:
        submission_file = TEMPLATES_DIR / "submission_titanic.csv"
        if not submission_file.exists():
            print("  [ERROR] submission_titanic.csv not found in templates")
            for bid in actionable:
                set_status(bid, "failed", "template missing")
            return False

        run_kaggle_cli(
            [
                "competitions",
                "submit",
                "-c",
                "titanic",
                "-f",
                str(submission_file),
                "-m",
                "Badge Collector automated submission",
            ]
        )
        print("  [OK] Submitted to Titanic competition")

        for bid in actionable:
            set_status(bid, "earned", "competition=titanic")
        return True

    except Exception as e:
        print(f"  [FAIL] Titanic submission: {e}")
        for bid in actionable:
            set_status(bid, "failed", str(e))
        return False


def _submit_playground(username: str) -> bool:
    """Submit to a Playground competition to earn Playground Competitor.

    Downloads the competition's sample_submission.csv and submits it.
    """
    if not should_attempt("playground_competitor"):
        return True

    set_status("playground_competitor", "attempting")
    try:
        comp = _find_competition_by_category("playground")
        if not comp:
            print("  [SKIP] No active Playground competition found")
            set_status("playground_competitor", "skipped", "no active playground competition")
            return False

        print(f"  Found playground competition: {comp}")

        # Download competition data to get sample_submission.csv
        tmp = make_temp_dir("-playground")
        dl_result = run_kaggle_cli(
            [
                "competitions",
                "download",
                comp,
                "--path",
                str(tmp),
            ],
            check=False,
        )
        if dl_result.returncode != 0:
            print(f"  [SKIP] Could not download {comp}; accept its rules on kaggle.com first")
            set_status("playground_competitor", "skipped", f"could not download {comp}")
            return False

        # Find and unzip if needed (zip-slip-safe)
        for zf in tmp.glob("*.zip"):
            _safe_extract(zf, tmp)

        # Find sample_submission
        submission_file = None
        for pattern in ["sample_submission*.csv", "sample*.csv", "submission*.csv"]:
            matches = list(tmp.glob(pattern))
            if matches:
                submission_file = matches[0]
                break

        if not submission_file:
            # Fall back: create a minimal submission from whatever CSVs are available
            print(f"  [SKIP] No sample_submission found for {comp}")
            set_status("playground_competitor", "skipped", f"no sample_submission for {comp}")
            return False

        result = run_kaggle_cli(
            [
                "competitions",
                "submit",
                "-c",
                comp,
                "-f",
                str(submission_file),
                "-m",
                "Badge Collector playground submission",
            ],
            check=False,
        )

        if result.returncode == 0:
            print(f"  [OK] Submitted to Playground: {comp}")
            set_status("playground_competitor", "earned", f"competition={comp}")
            return True
        else:
            print(f"  [FAIL] Playground submission failed for {comp}:")
            show_cli_output(result)
            set_status("playground_competitor", "failed", f"submit failed for {comp}")
            return False

    except Exception as e:
        print(f"  [FAIL] Playground submission: {e}")
        set_status("playground_competitor", "failed", str(e))
        return False


def _submit_community(username: str) -> bool:
    """Submit to a Community competition to earn Community Competitor.

    Community competitions are listed with `kaggle competitions list --group community`.
    """
    if not should_attempt("community_competitor"):
        return True

    set_status("community_competitor", "attempting")
    try:
        comp = _find_competition("--group", "community")
        if not comp:
            print("  [SKIP] No active community competition found")
            set_status("community_competitor", "skipped", "no active community competition")
            return False

        print(f"  Found community competition: {comp}")

        # Download sample submission
        tmp = make_temp_dir("-community")
        run_kaggle_cli(["competitions", "download", comp, "--path", str(tmp)], check=False)

        for zf in tmp.glob("*.zip"):
            _safe_extract(zf, tmp)

        submission_file = None
        for pattern in ["sample_submission*.csv", "sample*.csv"]:
            matches = list(tmp.glob(pattern))
            if matches:
                submission_file = matches[0]
                break

        if not submission_file:
            set_status("community_competitor", "skipped", f"no sample_submission for {comp}")
            return False

        result = run_kaggle_cli(
            [
                "competitions",
                "submit",
                "-c",
                comp,
                "-f",
                str(submission_file),
                "-m",
                "Badge Collector community submission",
            ],
            check=False,
        )

        if result.returncode == 0:
            print(f"  [OK] Submitted to community competition: {comp}")
            set_status("community_competitor", "earned", f"competition={comp}")
            return True
        else:
            print("  [FAIL] Submission failed:")
            show_cli_output(result)
            set_status("community_competitor", "failed", f"submit failed for {comp}")
            return False

    except Exception as e:
        print(f"  [FAIL] Community submission: {e}")
        set_status("community_competitor", "failed", str(e))
        return False


def _code_submission(username: str) -> bool:
    """Make a code-based submission to earn Code Submitter + Notebook Modeler.

    Creates a notebook that generates a submission file and submits via KKB.
    """
    badge_ids = ["code_submitter", "notebook_modeler"]
    actionable = [b for b in badge_ids if should_attempt(b)]
    if not actionable:
        return True

    for bid in actionable:
        set_status(bid, "attempting")

    try:
        tmp = make_temp_dir("-code-submit")
        nb_slug = resource_name("titanic-submit")

        # Create a notebook that generates a Titanic submission
        notebook_content = {
            "cells": [
                {
                    "cell_type": "code",
                    "execution_count": None,
                    "metadata": {},
                    "outputs": [],
                    "source": [
                        "import pandas as pd\n",
                        "import os\n",
                        "\n",
                        "# Read test data\n",
                        "test = pd.read_csv('/kaggle/input/titanic/test.csv')\n",
                        "\n",
                        "# Simple baseline: predict all 0\n",
                        "submission = pd.DataFrame({\n",
                        "    'PassengerId': test['PassengerId'],\n",
                        "    'Survived': 0\n",
                        "})\n",
                        "\n",
                        "# Save submission\n",
                        "submission.to_csv('submission.csv', index=False)\n",
                        "print(f'Submission shape: {submission.shape}')\n",
                        "print(submission.head())\n",
                    ],
                }
            ],
            "metadata": {
                "kernelspec": {
                    "display_name": "Python 3",
                    "language": "python",
                    "name": "python3",
                },
                "language_info": {"name": "python", "version": "3.10.0"},
            },
            "nbformat": 4,
            "nbformat_minor": 4,
        }
        (tmp / "notebook.ipynb").write_text(json.dumps(notebook_content, indent=2))

        metadata = {
            "id": f"{username}/{nb_slug}",
            "title": nb_slug,
            "code_file": "notebook.ipynb",
            "language": "python",
            "kernel_type": "notebook",
            "is_private": True,
            "enable_gpu": False,
            "enable_tpu": False,
            "enable_internet": False,
            "keywords": ["kaggle-badges", "titanic", "competition"],
            "competition_sources": ["titanic"],
            "dataset_sources": [],
            "kernel_sources": [],
            "model_sources": [],
        }
        (tmp / "kernel-metadata.json").write_text(json.dumps(metadata, indent=2))

        run_kaggle_cli(["kernels", "push", "-p", str(tmp)])
        print(f"  [OK] Code submission notebook pushed: {nb_slug}")
        print("  [MANUAL] The badges need a submission made from this notebook.")
        print(f"           When `kaggle kernels status {username}/{nb_slug}` shows COMPLETE,")
        print("           open the notebook on kaggle.com and choose Submit to competition.")

        # Pushing the notebook is not a submission, so nothing is earned yet.
        for bid in actionable:
            set_status(
                bid, "skipped", f"notebook={nb_slug} pushed; submit it from the notebook page"
            )
        return False

    except Exception as e:
        print(f"  [FAIL] Code submission: {e}")
        for bid in actionable:
            set_status(bid, "failed", str(e))
        return False


def _competition_modeler(username: str) -> bool:
    """Competition Modeler needs a competition notebook that uses a Kaggle model.

    Choosing and attaching a model is the user's decision (many need a licence
    to be accepted first), so nothing is pushed here.
    """
    if not should_attempt("competition_modeler"):
        return True

    print("  [MANUAL] Competition Modeler: in a notebook for any competition, use")
    print("           Add Input > Models to attach a model, then save a version.")
    set_status("competition_modeler", "skipped", "needs a model attached in the notebook editor")
    return False


def run(username: str) -> tuple[int, int]:
    """Run all Phase 2 badge actions. Returns (attempted, succeeded)."""
    actions = [
        ("Titanic submission", _submit_titanic),
        ("Playground submission", _submit_playground),
        ("Community submission", _submit_community),
        ("Code submission", _code_submission),
        ("Competition modeler", _competition_modeler),
    ]

    attempted = 0
    succeeded = 0

    for name, fn in actions:
        print(f"\n  --- {name} ---")
        attempted += 1
        if fn(username):
            succeeded += 1

    return attempted, succeeded
deprecation-and-migrationaddyosmani/agent-skillsManages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
performance-optimizationaddyosmani/agent-skillsOptimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall