Mastering the Kaggle CLI: Your Gateway to Automated Data Science
The Kaggle Command Line Interface (CLI) is a powerful tool that allows data scientists to interact with Kaggle’s offerings right from their terminal. Whether you’re looking to manage datasets, enter competitions, or share notebooks, the Kaggle CLI streamlines these processes, allowing for automation and efficiency without the need for a web browser. In this guide, we’ll dive deep into how to set up the Kaggle CLI and utilize its myriad features effectively.
- 1. Installation & Setup
- 2. Competitions
- List Competitions
- List Competition Files
- Download Competition Files
- Submit to a Competition
- List Your Submissions
- View Leaderboard
- 3. Datasets
- List Datasets
- List Files in a Dataset
- Download Dataset Files
- Initialize Dataset Metadata
- Create a New Dataset
- Create a New Dataset Version
- 4. Notebooks
- List Kernels
- Get Kernel Code
- Initialize Kernel Metadata
- Update Kernel
- Get Kernel Output
- Check Kernel Status
- 5. Models
- 6. Config
- 7. Tips
1. Installation & Setup
Before you can start using the Kaggle CLI, ensure you have Python version 3.10 or higher installed on your machine. To kick off the installation, execute the following command in your terminal:
bash
pip install kaggle
Once the installation is complete, obtaining your Kaggle credentials comes next. Head over to your Kaggle account settings and click on “Create New Token.” This action will download a kaggle.json file, which contains your username and API key needed for authentication.
To configure your environment variables, enter the following commands in your terminal:
bash
export KAGGLE_USERNAME=
export KAGGLE_API_KEY=
Make sure to replace <username> and <key> with the relevant information from your kaggle.json file. Now, you’re ready to leverage the full power of the Kaggle CLI!
2. Competitions
Kaggle competitions are stimulating challenges that allow you to apply your data science skills to real-world problems. The CLI facilitates seamless interaction with these competitions, allowing you to browse, download files, and submit solutions—all from the command line.
List Competitions
To discover new competitions, you can list them with:
bash
kaggle competitions list -s
This command provides a filtered view of competitions based on your search query, making it easier to find the ones that pique your interest.
List Competition Files
Want to know what data is available? Use:
bash
kaggle competitions files
This command lists all files associated with a specific competition, ensuring you know what resources you have before jumping into the challenge.
Download Competition Files
Need to download specific files? The command below allows for targeted downloads:
bash
kaggle competitions download
You can specify the -f flag to denote a specific file and use the -p option to set your preferred download directory.
Submit to a Competition
When you’re ready to make your entry, use:
bash
kaggle competitions submit
This command allows you to upload your solution file, along with an optional message to document your submission.
List Your Submissions
Curious about your past submissions? Run:
bash
kaggle competitions submissions
This command lists all your submissions, complete with scores and timestamps, so you can track your performance over time.
View Leaderboard
To check how you stack up against other participants, use:
bash
kaggle competitions leaderboard
Appending -s will limit the results to only the top entries, giving you a quick snapshot of the competition landscape.
3. Datasets
Kaggle Datasets are an invaluable resource for data scientists. The CLI commands for datasets allow you to efficiently search for, download, and manage datasets directly from your terminal.
List Datasets
To find datasets relevant to your projects, use:
bash
kaggle datasets list -s
This command filters datasets based on your specified search term, making it a breeze to explore available data.
List Files in a Dataset
If you’re eyeing a specific dataset, you can view its contents with:
bash
kaggle datasets files
This command details all available files in the selected dataset.
Download Dataset Files
Ready to acquire data? Use:
bash
kaggle datasets download
The --unzip flag is particularly handy if you want to automatically extract zipped files right away.
Initialize Dataset Metadata
Preparing to create or version a dataset? Initialize metadata with:
bash
kaggle datasets init -p
This command sets the stage for dataset creation, ensuring you have the necessary framework in place.
Create a New Dataset
To upload a new dataset, use:
bash
kaggle datasets create -p
This command enables you to post a fresh dataset from a specified folder.
Create a New Dataset Version
To update an existing dataset, employ:
bash
kaggle datasets version -p
This command uploads a new version while allowing you to annotate the changes made.
4. Notebooks
Kaggle Notebooks are essential for running executable code blocks and sharing analysis. The CLI allows you to manage these notebooks efficiently.
List Kernels
To find public notebooks related to your interests, run:
bash
kaggle kernels list -s
This command helps you discover kernels that might provide insights or inspiration.
Get Kernel Code
If you found a kernel you like, download its code with:
bash
kaggle kernels pull
This command pulls the kernel code right to your local file system.
Initialize Kernel Metadata
To prepare for kernel creation, use:
bash
kaggle kernels init -p
This will set up your environment for creating or updating a kernel.
Update Kernel
To upload your changes and update an existing kernel, use:
bash
kaggle kernels push -p
This command updates the specified kernel with your latest changes.
Get Kernel Output
To download outputs generated by a specific kernel, run:
bash
kaggle kernels output
This command ensures you have access to the results produced by the kernel.
Check Kernel Status
If you want to monitor kernel executions, check:
bash
kaggle kernels status
This command tells you if a kernel is running, complete, or failed.
5. Models
Kaggle Models enable sharing and reusing machine learning models. The CLI offers robust commands for managing these models seamlessly.
List Models
To find public models on Kaggle, use:
bash
kaggle models list -s
This allows you to sift through models that match your criteria.
Get a Model
To download a model and its associated metadata, execute:
bash
kaggle models pull
This command gives you access to a model right at your fingertips.
Initialize Model Metadata
Prepare for versioning or creating a new model with:
bash
kaggle models init -p
It sets the foundation for any model-related work.
Create a New Model
To upload a fresh model, use:
bash
kaggle models create -p
This command facilitates adding your new model to the Kaggle platform.
Update a Model
When updates are needed, run:
bash
kaggle models version -p
This action keeps your model up-to-date with relevant changes documented.
Delete a Model
If it’s time to remove a model from Kaggle, simply execute:
bash
kaggle models delete
A straightforward way to keep your workspace organized.
6. Config
Managing your Kaggle CLI configurations can significantly enhance your workflow. Here’s how to customize your settings.
View Config
To check your current configuration settings, including default competition or download path, use:
bash
kaggle config view
Set Config
To modify a configuration value, apply:
bash
kaggle config set
This command adjusts settings according to your preferences.
Unset Config
Need to revert to default behavior? Simply run:
bash
kaggle config unset
This removes the specified configuration, returning it to the original setting.
7. Tips
Here are some key pointers to maximize your Kaggle CLI experience:
- Use
-hor--helpafter any command for detailed options and supportive guidance. - Include
-vfor CSV output or-qfor quiet mode to reduce display clutter. - Remember to accept competition rules on the Kaggle website prior to participating in any challenge.
By mastering the Kaggle CLI, you’ll unlock new levels of productivity and creativity in your data science projects. Happy coding!
Inspired by: Source

