Image by Author
The Kaggle CLI (Command Line Interface) allows you to interact with Kaggle’s datasets, competitions, notebooks, and models directly from your terminal. This is useful for automating downloads, submissions, and dataset management without needing a web browser. Most of my GitHub Action workflows use Kaggle CLI for downloading or pushing datasets, as it is the fastest and most efficient way.
1. Installation & Setup
Make sure you have Python 3.10+ installed. Then, run the following command in your terminal to install the official Kaggle API:
To obtain your Kaggle credentials, download the kaggle.json file from your Kaggle account settings by clicking “Create New Token.”
Next, set the environment variables in your local system:
- KAGGLE_USERNAME=<username>
- KAGGLE_API_KEY=<key>
2. Competitions
Kaggle Competitions are hosted challenges where you can solve machine learning problems, download data, submit predictions, and see your results on the leaderboard.
The CLI helps you automate everything: browsing competitions, downloading files, submitting solutions, and more.
List Competitions
kaggle competitions list -s
Shows a list of Kaggle competitions, optionally filtered by a search term. Useful for discovering new challenges to join.
List Competition Files
kaggle competitions files
Displays all files available for a specific competition, so you know what data is provided.
Download Competition Files
kaggle competitions download [-f ] [-p ]
Downloads all or specific files from a competition to your local machine. Use -f to specify a file, -p to set the download folder.
Submit to a Competition
kaggle competitions submit -f -m ""
Upload your solution file to a competition with an optional message describing your submission.
List Your Submissions
kaggle competitions submissions
Shows all your previous submissions for a competition, including scores and timestamps.
View Leaderboard
kaggle competitions leaderboard [-s]
Displays the current leaderboard for a competition. Use -s to show only the top entries.
3. Datasets
Kaggle Datasets are collections of data shared by the community. The dataset CLI commands help you find, download, and upload datasets, as well as manage dataset versions.
List Datasets
Finds datasets on Kaggle, optionally filtered by a search term. Great for discovering data for your projects.
List Files in a Dataset
Shows all files included in a specific dataset, so you can see what’s available before downloading.
Download Dataset Files
kaggle datasets download / [-f ] [--unzip]
Downloads all or specific files from a dataset. Use –unzip to automatically extract zipped files.
Initialize Dataset Metadata
Creates a metadata file in a folder, preparing it for dataset creation or versioning.
Create a New Dataset
kaggle datasets create -p
Uploads a new dataset from a folder containing your data and metadata.
Create a New Dataset Version
kaggle datasets version -p -m ""
Uploads a new version of an existing dataset, with a message describing the changes.
4. Notebooks
Kaggle Notebooks are executable code snippets or notebooks. The CLI allows you to list, download, upload, and check the status of these notebooks, which is useful for sharing or automating analysis.
List Kernels
Finds public Kaggle notebooks (kernels) matching your search term.
Get Kernel Code
Downloads the code for a specific kernel to your local machine.
Initialize Kernel Metadata
Creates a metadata file in a folder, preparing it for kernel creation or updates.
Update Kernel
Uploads new code and runs the kernel, updating it on Kaggle.
Get Kernel Output
kaggle kernels output / -p
Downloads the output files generated by a kernel run.
Check Kernel Status
Shows the current status (e.g., running, complete, failed) of a kernel.
5. Models
Kaggle Models are versioned machine learning models you can share, reuse, or deploy. The CLI helps manage these models, from listing and downloading to creating and updating them.
List Models
Finds public models on Kaggle matching your search term.
Get a Model
Downloads a model and its metadata to your local machine.
Initialize Model Metadata
Creates a metadata file in a folder, preparing it for model creation.
Create a New Model
Uploads a new model to Kaggle from your local folder.
Update a Model
Uploads a new version of an existing model.
Delete a Model
Removes a model from Kaggle.
6. Config
Kaggle CLI configuration commands control default behaviors, such as download locations and your default competition. Adjust these settings to make your workflow smoother.
View Config
Displays your current Kaggle CLI configuration settings (e.g., default competition, download path).
Set Config
Sets a configuration value, such as default competition or download path.
Unset Config
Removes a configuration value, reverting to default behavior.
7. Tips
- Use -h or –help after any command for detailed options and usage
- Use -v for CSV output, -q for quiet mode
- You must accept competition rules on the Kaggle website before downloading or submitting to competitions
Abid Ali Awan (@1abidaliawan) is a certified data scientist professional who loves building machine learning models. Currently, he is focusing on content creation and writing technical blogs on machine learning and data science technologies. Abid holds a Master’s degree in technology management and a bachelor’s degree in telecommunication engineering. His vision is to build an AI product using a graph neural network for students struggling with mental illness.