KaggleDownloader
KaggleDownloader is a Python class designed to interact with Kaggle, enabling users to authenticate, search, download, and extract datasets. The class can be used both interactively in Jupyter Notebooks or via the command line.
Prerequisites
Before using the KaggleDownloader class, make sure you have:
- A Kaggle API token, available from your Kaggle account under "API" (https://www.kaggle.com/settings).
- Python 3.x installed.
Section 1: Using KaggleDownloader in a Jupyter Notebook
You can import and use KaggleDownloader directly within a Jupyter Notebook. Below is a step-by-step guide to authenticate and download datasets using the class methods.
1.1 Example Code
import kaggle_downloader as kd # Assuming you've saved the class in kaggle_downloader.py
import pandas as pd
# Initialize KaggleDownloader
downloader = kd.KaggleDownloader(api_token_path="./kaggle.json")
# Authenticate with Kaggle API
downloader.authenticate_kaggle()
# Search for datasets related to a theme
downloader.search_datasets("netflix")
# Download a specific dataset by its slug
downloader.download_dataset("shivamb/netflix-shows")
df = pd.read_csv("./netflix_titles.csv", delimiter=',', encoding="utf-8", encoding_errors="replace")
df.head()
1.2 Available Methods
get_api_token_path(): Returns the path to the primary Kaggle API token file.get_alternative_token_path(): Returns the path to the alternative Kaggle API token file.get_path_downloads(): Returns the download directory path.set_api_token_path(new_path): Sets a new path for the Kaggle API token.set_alternative_token_path(new_path): Sets a new path for the alternative Kaggle API token.set_path_downloads(new_path): Sets a new path for downloaded datasets.authenticate_kaggle(): Authenticates with the Kaggle API by loading credentials from the token file.authenticate_with_credentials(): Prompts the user to manually enter Kaggle credentials and saves them to a file.search_datasets(dataset_theme): Searches Kaggle for datasets matching a given keyword or theme.download_dataset(dataset_slug): Downloads a dataset from Kaggle to the specified directory.extract_zip(zip_file): Extracts a downloaded zip file to the download directory.check_kaggle_json(): Checks if the Kaggle API token file exists at either the primary or alternative path.create_download_directory(path): Creates the directory where datasets will be saved, if it doesn't already exist.
Section 2: Using KaggleDownloader via Command-Line Interface (CLI)
Alternatively, you can use the KaggleDownloader class via the command line. The main() method allows users to run the class and download datasets by specifying the dataset slug as an argument.
2.1 Example CLI Usage
-
First, make sure your script is executable:
chmod +x kaggle_downloader.py
-
Use the following command to download a dataset from Kaggle:
python kaggle_downloader_package/kaggle_downloader.py benroshan/ecommerce-data
This will authenticate with Kaggle (based on your kaggle.json token file) and download the dataset to the directory specified in path_downloads (or the current working directory by default).
2.2 CLI Arguments
dataset_slug: The Kaggle dataset identifier (slug) that you want to download, e.g.,benroshan/ecommerce-data.
Notes
- Ensure you have a Kaggle API token in place (
kaggle.json). - You can specify alternative token paths in case the default one isn't used.
- If you prefer to manually upload your Kaggle username and key, our KaggleDownloader will ask for them as it cannot find the kaggle.json file.
- Large datasets will be automatically unzipped if downloaded as zip files.
- The CLI interface will parse arguments and invoke necessary functions for a seamless experience.
Customization:
- Replace
kaggle_downloader.pywith the actual file name if different. - Adjust the class import path (
from kaggle_downloader import KaggleDownloader) if you organize your code differently.
Contributing
Feel free to contribute to this project by submitting issues, feature requests, or pull requests on GitHub.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Author
Mariano Gobea Alcoba
Email: gobeamariano@gmail.com
Metadata
Release files for kaggle-downloader-package 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kaggle_downloader_package-0.1.7.tar.gz | 5.4 kB | Without provenance | Details for kaggle_downloader_package-0.1.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kaggle_downloader_package-0.1.7-py3-none-any.whl | Python 3 | none | any | Details for kaggle_downloader_package-0.1.7-py3-none-any.whl |
Total release size: 11.6 kB
Release files / kaggle_downloader_package-0.1.7.tar.gz
| Download URL | kaggle_downloader_package-0.1.7.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2551dc9fc148bd94d561822f271732c864f9484af168b807d772ab400544de3a
|
|
BLAKE2b-256 checksum How to use checksums |
ef0ec84a9fd17d5f17e14f2887e81f820c15a86e2e20ab42912aa9d89775f91c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.12.3 Darwin/23.5.0
|
Release files / kaggle_downloader_package-0.1.7-py3-none-any.whl
| Download URL | kaggle_downloader_package-0.1.7-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
18e523fc86a5cfcf081df423ed2429805d1bf4e0ec6060bf897d59ba1fd973a3
|
|
BLAKE2b-256 checksum How to use checksums |
bfe841087ecf466101f1eb03d448d3ada2b33b86a417f5c2c98e5db415617110
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.12.3 Darwin/23.5.0
|
Security for kaggle-downloader-package 0.1.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.