How to use Kaggle API and download a dataset by a single command

Pavol Travnik
2 min readMar 28, 2023

First steps

Kaggle is a platform for data science and machine learning competitions, as well as a collaborative community for data scientists and machine learning enthusiasts. Kaggle allows users to find, share, and analyze datasets, as well as to participate in machine learning competitions and learn from other professionals in the field.

Prerequisites: installed Python and pip

1. Install kaggle on your comuputer

pip install kaggle

2. Register and create api key

Click on Right top corner profile icon > “Account” > Create New API Token

This will download a file kaggle.json with a content like this:

{"username":"pavoltravnik","key":"4947145f624f168fd0db5847dce59aa8"}

3. Save API token

You have to save token first you have two options.

Copy the file to your .kaggle folder

cp ~/Downloads/kaggle.json ~/.kaggle/kaggle.json

Or paste the content it directly there.

echo '{"username":"pavoltravnik","key":"4947145f624f168fd0db5847dce59aa8"}'  > ~/.kaggle/kaggle.json

4. Find a competion and join

Just search for any competition on this site https://www.kaggle.com/competitions

5. Download and unzip latest downloaded zip file

You can find a command to download any dataset on the bottom of the page for each competition in the Data page.

Then just add the script to unzip the latest zip file.

kaggle competitions download -c house-prices-advanced-regression-techniques && \
LATEST_ZIP=$(ls -t *.zip | head -n 1) && unzip "$LATEST_ZIP" -d "$(basename "$LATEST_ZIP" .zip)"

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Pavol Travnik
Pavol Travnik

No responses yet

Write a response