Easy way to download datasets from kaggle from your terminal

In this blog post I would like to show you how to use kaggles api. And not only that, I will show you how to directly use this API from Jupyter. It's straightforward and shouldn't take longer than 5 minutes. Let's get started!

First of all, log in into your kaggle account and go to "Your Account". Scroll down until you find the section API. Click on "Create New API Token".

image info

Next, upload your downloaded token into a directory to which you have access to. In this blogpost, I use my Cloud Working Space on Paperspace (how to easily set up your own working space in Paperspace click here.

image info

Note however, that kaggle expects your token to be at a specific folder: ~/.kaggle/kaggle.json on Linux, OSX, and other UNIX-based operating systems, and at C:\Users<Windows-username.kaggle\kaggle.json on Windows. So that's what we will do next. Just open your Terminal and move your token to the expected folder.

image info

And that's it, you can now use the kaggle API! If you (like me) use a remote computing instance, we don't want other user to possible use our token. We can prevent this by typing:

image info

Let's see how the kaggle API works. First of all, we need to pip install the package.

image info

If you are looking for a specific dataset, you can now use the kaggle API and simply type:

image info

If you want to download data from this API, you write:

image info

In that way you can easily access kaggle datasets and make that work even on cloud computing instances.

Stay tuned for the next blogpost!

Lasse