1 minute read

Kaggle Section: Creating Kaggle API

  • To do this, go to kaggle.com/ and open your user settings page.

kaggle_colab_1

  • Next, scroll down to the API access section and click generate to download an API key.

kaggle_colab_2

This will download a file called kaggle.json to your computer. You’ll use this file in Colab to access Kaggle datasets and competitions.

Colab Section: Accessing kaggle data in Colab

# Run this cell and select the kaggle.json file downloaded
# from the Kaggle account settings page.
from google.colab import files
files.upload()
  • Let’s make sure the kaggle.json file is present.
# Let's make sure the kaggle.json file is present.
!ls -lha kaggle.json
-rw-r--r-- 1 root root 64 Jun  1 20:46 kaggle.json
  • Install Kaggle API client
# Next, install the Kaggle API client.
!pip install -q kaggle
# The Kaggle API client expects this file to be in ~/.kaggle,
# so move it there.
!mkdir -p ~/.kaggle
!cp kaggle.json ~/.kaggle/

# This permissions change avoids a warning on Kaggle tool startup.
!chmod 600 ~/.kaggle/kaggle.json
  • List of available datasets
# List available datasets.
!kaggle datasets list
  • Copy or Download Datasets locally
# Copy the stackoverflow data set locally.
!kaggle datasets download -d stackoverflow/stack-overflow-2018-developer-survey
!head ~/.kaggle/datasets/stackoverflow/stack-overflow-2018-developer-survey/survey_results_public.csv

References

Comments