Registry / ai-ml / kagglehub

kagglehub

JSON →
library1.0.2pypypi✓ verified 24d ago

KaggleHub is a Python library that provides a unified interface to programmatically access and download Kaggle resources, primarily models and datasets, outside of the Kaggle platform. It aims to standardize resource paths and simplify integration with other ML frameworks. The current version is 1.0.0, and the library has a frequent release cadence, with minor versions often released every few weeks.

pip install kagglehub
INSTALL
IMPORT
SIG · KAGGLEHUB
K
kagglehub
ai-mlpythonv1.0.2
Install
3.0s avg
Import
1203ms
Disk
29MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 1.356s · 30.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.0s · import 1.050s · 32MB
29MB installed
● package 29MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

model_download
from kagglehub import model_download
dataset_download
from kagglehub import dataset_download
hf_model_download
from kagglehub import hf_model_download
from kagglehub import model.hf_model_download
hf_model_download is a top-level function in kagglehub, not nested under a 'model' submodule.

This quickstart demonstrates how to download a pre-trained model using `kagglehub.model_download()`. Replace the `model_handle` with the desired model's identifier. For authentication, ensure your Kaggle API credentials (username and key) are set as environment variables (`KAGGLE_USERNAME`, `KAGGLE_KEY`) or available in a `~/.kaggle/kaggle.json` file.

import os from kagglehub import model_download # Ensure KAGGLE_USERNAME and KAGGLE_KEY environment variables are set # or a kaggle.json file exists in ~/.kaggle/ # Example: Download a specific version of a model model_handle = 'google/vit/tensorflow/vit-base-patch16-224-fe/2' model_path = model_download(model_handle) print(f"Downloaded model path: {model_path}") # To run this, you need to have Kaggle API credentials configured. # For local testing, ensure your `KAGGLE_USERNAME` and `KAGGLE_KEY` # environment variables are set or a `kaggle.json` file is present.
kagglehub --version
Debug
Known issues
gotchaKaggleHub (this library) is distinct from the general 'kaggle' API client. While both interact with Kaggle, KaggleHub focuses specifically on standardizing the download and access of models and datasets, often integrating with other ML frameworks. Users familiar with `kaggle.api` for broader tasks (competitions, submitting, etc.) should note the different purpose and API.
fix
Understand the scope: `kagglehub` for resource downloading, `kaggle` client for broader API interaction. Don't mix import paths or assume identical functionality.
affects: All versions
gotchaResource handles for models and datasets follow a specific `owner/model-name/framework/variation/version` (for models) or `owner/dataset-slug` (for datasets) format. Incorrectly formatted handles will lead to download failures.
fix
Always refer to the official KaggleHub documentation or the model/dataset page on Kaggle for the exact resource handle. Pay close attention to slashes and components.
affects: All versions
gotchaAuthentication requires Kaggle API credentials. This typically means setting `KAGGLE_USERNAME` and `KAGGLE_KEY` environment variables or having a valid `kaggle.json` file in `~/.kaggle/`.
fix
Ensure your environment variables are correctly set or your `kaggle.json` file is present and contains valid credentials. If running in a Kaggle notebook, authentication is usually handled automatically.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'kagglehub'
The `kagglehub` library is not installed in your Python environment or the environment where you are running your code is not the one where `kagglehub` was installed.
fix
Install the library using pip: `pip install kagglehub`
401 Client Error: You don't have permission to access resource at URL: ... Unauthenticated
You are attempting to access a Kaggle resource (private or requiring consent) without proper authentication. This can be due to missing Kaggle API credentials, incorrect credentials (e.g., using a regular API token instead of a legacy one for `kagglehub.login()`), or misconfigured environment variables/files.
fix
Ensure you are authenticated. Options include: 1) Calling `kagglehub.login()` and providing your Kaggle API token (preferably a 'Legacy API credentials' token from Kaggle settings). 2) Setting `KAGGLE_USERNAME` and `KAGGLE_KEY` environment variables. 3) Storing your `kaggle.json` file in `~/.kaggle/kaggle.json` or `~/.kaggle/access_token`. If in Google Colab, use Colab secrets for `KAGGLE_API_TOKEN`.
ModuleNotFoundError: No module named 'kaggle.competitions'
You are trying to import modules that are part of the older `kaggle` CLI tool or specific to the Kaggle Notebook environment (Kaggle Kernels) into a local Python environment where these modules are not available.
fix
The `kagglehub` library focuses on programmatic access to models and datasets. If you need to interact with competitions (e.g., downloading competition data), you should use the `kaggle` command-line interface directly (`!kaggle competitions download ...`) or ensure you are running your code within a Kaggle Notebook where `kaggle.competitions` is available. The `kagglehub` library itself does not expose a `kaggle.competitions` module.
Resource not found at URL: https://www.kaggle.com/datasets/... 404 - Not Found
The specified Kaggle resource (model or dataset) handle, path, or version is incorrect or does not exist, or the resource is private and you lack the necessary permissions even if authenticated.
fix
Double-check the resource's handle (e.g., `owner_slug/dataset_slug`), the specific file path within the resource, and the version number. Ensure the resource is public or that your authentication grants access to it.
ImportError: The 'dataset_load' function requires the 'pandas-datasets' extras. Install them with 'pip install kagglehub[pandas-datasets]'
When using `kagglehub.dataset_load()` with a specific adapter (e.g., for Pandas, Hugging Face, or Polars DataFrames), the necessary optional dependencies for that adapter were not installed.
fix
Install `kagglehub` with the required optional dependencies for the adapter you wish to use. For Pandas, use: `pip install kagglehub[pandas-datasets]`. For Hugging Face: `pip install kagglehub[hf-datasets]`. For Polars: `pip install kagglehub[polars-datasets]`.
Upgrade
Version history
1.0.2latest on PyPI · released Jun 9, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
3 hits · last 30 days
node
2
Resources
kagglehub — pip install kagglehub · libregistry