Getting the Kaggle CLI working without the usual headaches

Table of Contents

Doing Kaggle from the terminal instead of clicking around the website is so much nicer once it’s set up, but the first-time setup has a couple of spots that trip everyone (me included). Here’s the whole thing, including the errors you’ll probably hit.

Install it

pip install kaggle

That gives you the kaggle command for pulling data, submitting predictions, and browsing competitions without leaving the terminal.

Hook up your credentials

  1. Log in at kaggle.com/settings
  2. Find the API section and click Create New Token
  3. A kaggle.json file downloads. That’s your credentials, so don’t commit it anywhere.
  4. Move it where the CLI expects:
    • Linux/macOS: ~/.kaggle/kaggle.json
    • Windows: C:\Users\<username>\.kaggle\kaggle.json
  5. On Linux/macOS, lock down the permissions: chmod 600 ~/.kaggle/kaggle.json

The commands you’ll actually use

CommandWhat it does
kaggle competitions listBrowse active competitions
kaggle competitions download -c titanicDownload competition data
kaggle competitions submit -c titanic -f submission.csv -m "message"Submit predictions
kaggle competitions submissions -c titanicSee your submission history
kaggle datasets list -s "keyword"Search public datasets

When it breaks (and it will, once)

If you want to confirm everything’s wired up, run python scripts/verify_kaggle_cli.py and it’ll check the setup for you.

Probably a small audience for this knowledge, but I’m always looking out for CLI’s so I can do as much in command line as I can.