Setting up Kaggle API
Setting up Kaggle API on Mac/Linux
Hello there!
If you are like me and want to use Kaggle API instead of manual clicks here and there on the Kaggle website to get your task done, this post is for you! Note: This post is most useful for folks using a Mac or a Linux environment.
Let’s get started!
1. Installing the library
There are two ways to do this:
2. Setting up the API token
If you are like me and want to use Kaggle API instead of manual clicks here and there on the Kaggle website to get your task done, this post is for you! Note: This post is most useful for folks using a Mac or a Linux environment.
Let’s get started!
1. Installing the library
There are two ways to do this:
- Using the command
pip install kaggle
- Using the command
pip install --user kaggle
sudo pip install kaggle
if you don’t want to face unnecessary problems or unless you know what you’re doing.2. Setting up the API token
- Go to the kaggle website.
- Click on
Your profile
button on the top right and then selectMy Account
. - Scroll down to the
API
section and click on theCreate New API Token
button. - It will initiate the download of a file call
kaggle.json
. Save the file at a known location on your machine.
.json
file at the correct location- Move the downloaded file to a location
~/.kaggle/kaggle.json
. If you don’t have the .kaggle folder in your home directory, you can create one using the command:mkdir ~/.kaggle
- Now move the downloaded file to this location using:
mv <location>/kaggle.json ~/.kaggle/kaggle.json
- You need to give proper permissions to the file (since this is a hidden folder):
chmod 600 ~/.kaggle/kaggle.json
- Run the command
kaggle competitions list
. - If you see a list of active competitions, you’re done setting the API up.
- If you don’t, try looking at the location of kaggle by using the command:
pip uninstall kaggle
- So if you find the location such as
~/.local/bin/kaggle
, try running the kaggle command as:~/.local/bin/kaggle competitions list
- Now that you’ve set up the API, you can start using it. You can get the help for the api using
kaggle --help
. If you want help regarding a more specific command use--help
after that command. For example,kaggle dataset --help
. For a more detailed description of everything and other information, go to the kaggle-api GitHub repository.
Comments
Post a Comment