Connect any database. Ask in plain English.

Try free
← Blog

Kaggle API: Install the CLI, Set Up the New Token or kaggle.json, Download Data, Tested (2026)

Kaggle's CLI 2.2.5 signs in four ways: kaggle auth login, a KGAT_ token in KAGGLE_API_TOKEN or ~/.kaggle/access_token, or the legacy kaggle.json. We installed it in a fresh venv on 1 December 2026, hit a missing-module error on the very first command, downloaded a public dataset with no credentials, and list the exact messages behind 401, 403 and a token saved in the wrong file.

Fastero Dev TeamFastero Dev Team2026-12-01Last updated: 2026-12-02

We installed Kaggle's command-line tool and its Python library, kagglehub, in a fresh virtual environment on Windows 11 on 1 December 2026, read the CLI's documentation, changelog and source code on GitHub, and ran every command that works without an account. The first command failed, public downloads worked signed out, and the error messages below come from our terminal or from the tool's own code.

The short answer: install with pipx install kaggle or pip install kaggle (Python 3.11 or later; the current release is 2.2.5). Sign in with kaggle auth login, which opens a browser, or generate an API token under Settings › API on kaggle.com: it starts with KGAT_ and goes in the KAGGLE_API_TOKEN environment variable or a file at ~/.kaggle/access_token. kaggle.json still works, but Kaggle now files it under "Legacy API Credentials". Then kaggle datasets download owner/name --unzip fetches a dataset, and public datasets download even when signed out. Competitions refuse until you join and accept the rules on the website. Checked 1 December 2026.

Fastero

Connect your database. Ask questions. Get dashboards.

Postgres, BigQuery, Snowflake, and 10+ sources — live-connected, AI-powered, no dashboard builder learning curve.

Try free →

Kaggle CLI cheat sheet

A cheat sheet table of Kaggle CLI 2.2.5 and kagglehub 1.0.3 commands: install, version, two ways to sign in, dataset search, files and download, competition download and submit, kernels init, push, status and output, kaggle quota, and kagglehub dataset_download and dataset_load, with a column saying which ones needed no sign-in in our test

The commands this guide covers, with the sign-in column from our own runs on 1 December 2026: public dataset files and downloads worked with no credentials, everything else asked us to sign in.

How to install the Kaggle CLI

Kaggle's docs say "Note: Ensure you have Python 3.11+." and recommend pipx or uv, which keep the CLI in its own environment. Plain pip inside a virtual environment works too, and it's what we used:

python -m venv .venv
.venv\Scripts\activate            # macOS and Linux: source .venv/bin/activate
pip install kaggle
kaggle --version

That installed kaggle 2.2.5, kagglesdk 0.1.38 and python-dateutil 4.0.0. The first command then failed:

$ kaggle --version
Traceback (most recent call last):
  [traceback trimmed]
  File "...\site-packages\kaggle\models\upload_file.py", line 22, in <module>
    import six
ModuleNotFoundError: No module named 'six'
exit code: 1

Every kaggle command fails this way, because the CLI imports a module it never declared and used to get through python-dateutil, which dropped it in version 4.0.0. The changelog lists the fix under its next, unreleased version. Until then:

$ pip install six
$ kaggle --version
Kaggle CLI 2.2.5
exit code: 0

Two other install errors the docs cover: error: externally-managed-environment on recent Debian and Ubuntu (use pipx or uv), and Command kaggle not found, which means pip's scripts folder isn't on your PATH (~/.local/bin for a user install on Linux).

Kaggle API key: the new token, OAuth or kaggle.json

The CLI accepts four kinds of credentials. As of version 2.2.5:

Method Where it lives Best for
kaggle auth login A browser sign-in; the CLI caches it in ~/.kaggle/credentials.json Your own laptop
KAGGLE_API_TOKEN An environment variable holding a KGAT_... token CI, servers, Colab
~/.kaggle/access_token A text file holding only the KGAT_... token Your own laptop
kaggle.json (legacy) {"username": "...", "key": "..."} in ~/.kaggle/, or KAGGLE_USERNAME and KAGGLE_KEY Older scripts and tools

To get a token, sign in to kaggle.com, open Settings, and in the API section click "Generate New Token". The kaggle.json file comes from a separate button under "Legacy API Credentials", labeled "Create Legacy API Key". The CLI's own sign-in message recommends the first row: "Recommended: log in with OAuth via a web-based authorization flow."

The token arrived in two steps: token files need CLI 1.8 or later, which reached PyPI on 21 November 2025, and kaggle auth login was documented in 2.1.1 (5 May 2026). That explains two reports on the CLI's GitHub: someone generates a new token, runs an old CLI, and gets OSError: Could not find kaggle.json. Versions before 1.8 only know the legacy username and key. Upgrading fixes it, but 1.8.0 and later need Python 3.11, so on an older Python pip quietly keeps installing 1.7.4.5, the last release that allows 3.7.

Where does kaggle.json go?

  • macOS and Linux: ~/.kaggle/kaggle.json. On Linux, if ~/.kaggle doesn't exist, the CLI uses ~/.config/kaggle/ instead.
  • Windows: C:\Users\<you>\.kaggle\kaggle.json.
  • Anywhere else: set KAGGLE_CONFIG_DIR to the folder that holds it.

The token file is different: the CLI reads ~/.kaggle/access_token from your home folder whatever KAGGLE_CONFIG_DIR says, and on Windows it also accepts access_token.txt, in case Notepad added the extension. On macOS and Linux, lock the file down with chmod 600, or the CLI prints this warning (from its code, with your full path; Windows skips the check):

Warning: Your Kaggle API key is readable by other users on this system! To fix this, you can run 'chmod 600 /home/you/.kaggle/kaggle.json'

When several are set, the CLI tries an access token first, then the legacy key, then the OAuth login. Never paste a token into a notebook you share. Inside a Kaggle notebook you don't need one for kagglehub, and other keys belong in Kaggle Secrets, read with UserSecretsClient, which is "only functional within the Kaggle notebook execution environment". In Colab, keep the token in the Secrets panel under the name KAGGLE_API_TOKEN, which kagglehub reads directly; our Colab secrets guide covers the panel.

kaggle datasets download: datasets from the command line

A dataset's reference is the last two parts of its URL, owner then name: willianoliveiragibin/pixar-films, for example. The CLI's auth docs say "Some commands are allowed logged out, including help/version and selected public dataset file/download flows." We checked that with no credentials anywhere on the machine:

$ kaggle datasets files willianoliveiragibin/pixar-films
name                 size  creationDate
-------------------  ----  --------------------------
pixar_films new.csv  2939  2025-03-07 22:43:52.335000
exit code: 0
 
$ kaggle datasets download willianoliveiragibin/pixar-films -p data --unzip
Dataset URL: https://www.kaggle.com/datasets/willianoliveiragibin/pixar-films
License(s): CC0-1.0
Downloading pixar-films.zip to data
100%|##########| 1.64k/1.64k [00:00<00:00, 1.07MB/s]
exit code: 0

The zip was 1.64 KB; --unzip left the 2,939-byte CSV in data and deleted the archive. Searching is different: kaggle datasets list -s "air quality" printed the sign-in message and exited with 1, so list needs credentials even for public data.

Options worth knowing:

  • -f file.csv downloads one file instead of the whole dataset.
  • -p folder picks the folder; -o re-downloads over an existing copy.
  • owner/dataset/3 downloads version 3 instead of the latest.
  • --unzip with -f extracts a large file that Kaggle serves inside a zip of the same name.

One catch from our run: with -f "pixar_films new.csv", the file arrived as pixar_films%20new.csv, its space still URL-encoded. Rename it, or download the whole dataset with --unzip, which kept the real name.

Download competition data, and why you get 403

Competition files need a signed-in account that has joined the competition. Kaggle's tutorial says you must "join the competition and accept the competition's rules on the Kaggle website", and the CLI can't do that step for you. Then:

kaggle competitions download titanic -p data --unzip
kaggle competitions submit titanic -f submission.csv -m "first try" --wait

Use the competition's short name from its URL (titanic), not the whole URL: one user's 403, saying the permission competitions.participate was denied, went away when they passed the name alone. --wait blocks until the submission is scored, up to 12 hours by default, and exits with a non-zero code if scoring fails, so it can stop a pipeline.

Push and run a notebook: kaggle kernels push

The CLI calls notebooks "kernels". To run a local .ipynb on Kaggle's machines with no browser open:

  1. Create the metadata file. kaggle kernels init -p mynb writes mynb/kernel-metadata.json. Edit it:

    {
      "id": "your-username/sales-forecast",
      "title": "Sales Forecast",
      "code_file": "sales-forecast.ipynb",
      "language": "python",
      "kernel_type": "notebook",
      "is_private": "true",
      "enable_gpu": "true",
      "enable_internet": "false",
      "machine_shape": "NvidiaTeslaT4",
      "dataset_sources": ["willianoliveiragibin/pixar-films"]
    }

    The slug is the title in lowercase with dashes. If you leave them out, is_private defaults to true, and enable_gpu and enable_internet to false, so a notebook that installs packages needs enable_internet switched on.

  2. Push it. kaggle kernels push -p mynb uploads the notebook, creates a new version and starts running it. Its code then prints a line like this:

    Kernel version 1 successfully pushed.  Please check progress at <url>

    Add --accelerator NvidiaTeslaT4 for the two T4 GPUs, -t 3600 to stop it after an hour, or --no-run to save a version without running it.

  3. Check on it. kaggle kernels status you/sales-forecast, with your username in place of you. The states in Kaggle's SDK include queued, running, complete and error.

  4. Collect the results. kaggle kernels output you/sales-forecast downloads the files the run wrote (-p out picks the folder), and --file-pattern ".*\.csv$" limits it to CSVs.

These commands need credentials, so we couldn't run them signed out; they come from Kaggle's docs, the CLI's --help and its source. To pull an existing notebook down first, kaggle kernels pull your-username/slug -m fetches it with its metadata. How long a run may take, and the GPU quota it spends, are in our Kaggle Notebooks guide. To execute a notebook on your own machine instead, see running a notebook from the command line.

Connect any database. Ask in plain English.

Start free →

kaggle quota: GPU hours left

kaggle quota, added in 2.2.1, shows the week's GPU and TPU hours as used, remaining, total and refreshAt, and kaggle quota -v prints the same as CSV. Signed out, it prints the sign-in message. What the quota is and how to spend it is covered in our Kaggle GPU guide.

kagglehub: the Kaggle API from Python

kagglehub is Kaggle's Python library for the same downloads. It reads the same token sources as the CLI, plus a Colab secret, and it too needs no sign-in for public datasets. We ran this with kagglehub 1.0.3 and pandas 3.1.2, signed out (progress bar and cache folder trimmed from the output):

import kagglehub
from kagglehub import KaggleDatasetAdapter
 
path = kagglehub.dataset_download("willianoliveiragibin/pixar-films")
print(path)
 
df = kagglehub.dataset_load(
    KaggleDatasetAdapter.PANDAS,
    "willianoliveiragibin/pixar-films",
    "pixar_films new.csv",
)
print(df.shape)
print(df[["film", "release_date", "box_office_worldwide"]].head(3).to_string(index=False))
Downloading to ...\datasets\willianoliveiragibin\pixar-films\1.archive...
Extracting files...
...\datasets\willianoliveiragibin\pixar-films\versions\1
Download already complete (2939 bytes).
(28, 16)
        film release_date  box_office_worldwide
   Toy Story   1995-11-22             394436586
A Bug's Life   1998-11-25             363258859
 Toy Story 2   1999-11-24             511358276

dataset_load needs pip install "kagglehub[pandas-datasets]". Files are cached in ~/.cache/kagglehub/ (change it with KAGGLEHUB_CACHE, or pass output_dir), so the second call reused the download. Inside a Kaggle notebook, kagglehub attaches the dataset to the notebook instead of downloading it. Signed out, kagglehub.competition_download("titanic") ended with:

kagglehub.exceptions.UnauthenticatedError: User is not authenticated

Use the CLI for shell scripts, competitions and pushing notebooks; use kagglehub when the next line of code is pandas.

Kaggle API errors and how to fix them

What you see Why Fix
No module named 'six' kaggle 2.2.5 with python-dateutil 4.0.0 pip install six
"Authentication required to call the Kaggle API." No credentials, or the server rejected them: in 2.2.5 a 401 prints this kaggle auth login, or a new token
401 - Unauthorized or 401 Client Error: Unauthorized Older CLI versions: an expired key, or a competition you haven't joined New token; join the competition
403 Client Error: Forbidden Not joined, rules not accepted, or a full URL instead of the name Join and accept the rules on the website
Could not find kaggle.json A CLI older than 1.8 with a new token Upgrade on Python 3.11+
UnauthenticatedError kagglehub, signed out, on something that needs an account Set KAGGLE_API_TOKEN or kagglehub.login()

Since 2.2.5 the CLI adds a next step to 403 errors: "You don't have access to this resource." followed by "If this is a competition, you may need to accept its rules first" and a link to the rules page. A 404 gets "The resource was not found. Check the spelling of the reference you passed." and a 429 "You have been rate limited."

One mistake gets a clearer message soon. We put a fake KGAT_ token in kaggle.json as the key, and 2.2.5 replied only with "Authentication required to call the Kaggle API." A change merged into the CLI's main branch on 4 November 2026 makes it name the problem and point to ~/.kaggle/access_token or KAGGLE_API_TOKEN instead, once it's released. Until it ships: tokens starting KGAT_ never go in kaggle.json.

After the download: when the data is for your team

Kaggle is the place to get the data and train on it. If the CSV you downloaded is the start of a report other people will read, Fastero is an AI and data platform where people and AI agents work together on a team's data, and it picks up from the file. Download the file with the CLI first, then:

  • Upload the CSV to a Fastero project and ask about it in the AI chat, which writes and runs the SQL and builds dashboards and reports. It takes up to 10 files at a time, 50 MB each.
  • Open it in a notebook. Notebooks are standard .ipynb files, and they read the project's uploaded files by path with pandas, Excel files too.
  • Run the notebook on a cron schedule on the server, with no browser open, and keep keys in Secrets, which reach cells as environment variables.
  • Share it with a sign-in. Viewers are free, and the Free plan has no end date and needs no card. It includes $20 of AI usage to start, 500 MB of storage and 6 hours a day of notebook and Python run time, on a 1 CPU, 2 GB server per workspace; on Pro, bigger machines up to 8 CPUs and 32 GB, charged by the hour. Plans are on the pricing page.

Fastero's AI chat after a CSV of sample orders was attached: the request asks for a dashboard with daily revenue, revenue by channel, orders by region and revenue by product, and the reply lists the dashboard it built with 360 rows and $1.23M in total revenue

A CSV uploaded to Fastero's AI chat and turned into a dashboard. Sample data.

FAQ

Where do I find my Kaggle API key?

On kaggle.com, open your account's Settings and go to the API section. "Generate New Token" makes a token starting with KGAT_, for KAGGLE_API_TOKEN or ~/.kaggle/access_token. The older kaggle.json file is under "Legacy API Credentials".

Is kaggle.json deprecated?

Kaggle labels it legacy, and the CLI's help now points people to kaggle auth login or an API token instead. It still worked in CLI 2.2.5 on 1 December 2026, and we found no announced end date. New setups should use a token.

Do I need an API key to download Kaggle datasets?

Not for public datasets: in our test, kaggle datasets download, kaggle datasets files and kagglehub's dataset_download all worked with no credentials. Searching datasets, competition data, private datasets, uploads and pushing notebooks all need you signed in.

Why does kaggle competitions download give 403 Forbidden?

Almost always because the account hasn't joined the competition and accepted its rules on kaggle.com, which the CLI can't do for you. Also pass the competition's short name, such as titanic, rather than its full URL. Invitation-only competitions refuse anyone the host hasn't invited.

How do I use the Kaggle API in Google Colab?

Add your token to Colab's Secrets panel as KAGGLE_API_TOKEN and give the notebook access. kagglehub reads that secret directly. For the CLI, set os.environ["KAGGLE_API_TOKEN"] from userdata.get before the first kaggle command.

What's the difference between the kaggle CLI and kagglehub?

The kaggle CLI covers everything: datasets, competitions, notebooks, models, quota and submissions, from a shell. kagglehub is a Python library for downloading and uploading datasets, models and notebook outputs, and it can load a file straight into pandas. Both use the same credentials.

Sources

Read on 1 December 2026; versions are the ones pip installed that day.


Try Fastero free: upload the CSV you pulled from Kaggle, ask questions of it, and turn the answer into a dashboard your team signs in to read. No credit card required.

Ready to try it yourself?

Connect your database, ask questions in plain English, and get live dashboards — in under 2 minutes. No credit card required.

Follow Fastero on LinkedIn for new articles and examples.

Keep reading

Related articles

2026-12-02

Kaggle Datasets: Find a Good One, Download It 3 Ways, and the 200 GB Limits (2026)

Public Kaggle datasets download with no account: kagglehub fetched a 7.1 MB public-domain dataset in 1.8 seconds, signed out, on 2 December 2026. How to filter by file type, license and usability, the website, CLI and kagglehub routes with real output, Kaggle's 200 GB and 50-file limits, and the licenses on the 200 most-voted datasets (87 are CC0, 20 forbid commercial use).

kaggledatasetspython

2026-12-03

MNIST Dataset: 70,000 Digits, 5 Copies That Match Byte for Byte, and a 98.9% CNN in 38 Seconds on a CPU (2026)

MNIST is 70,000 handwritten digits, 28 by 28 pixels, split 60,000 for training and 10,000 for testing. LeCun's original page is now an empty folder, so we downloaded the copies in torchvision, Keras, Hugging Face, OpenML and Kaggle and hashed them: all five are identical. The IDX format with a 20-line parser, the real class counts (5,421 to 6,742 per digit), and four models timed on a laptop CPU, from 92.7% for logistic regression in 11 seconds to 98.9% for a small CNN in 38.

datasetsmachine-learningpytorch

2026-12-03

Iris Dataset: 150 Flowers, 5 Ways to Load It, and the 2 Rows That Differ Between Copies (2026)

The iris dataset is 150 flowers, 50 from each of three species, with four measurements in centimeters. We downloaded six copies and compared them with Fisher's 1936 table: UCI's iris.data and Kaggle's Iris Species differ in rows 35 and 38, while scikit-learn, seaborn, R and UCI's bezdekIris.data match it. Loading code for pandas, scikit-learn, seaborn, DuckDB and R, summary statistics, and baseline models that score 94% to 98% in cross-validation.

datasetsmachine-learningscikit-learn