import_kaggle
def import_kaggle():Import kaggle API, using Kaggle secrets kaggle_username and kaggle_key if needed
On Kaggle, credentials come from Kaggle secrets rather than the usual ~/.kaggle/kaggle.json, so getting an authenticated API client depends on where you are. import_kaggle handles both cases:
Import kaggle API, using Kaggle secrets kaggle_username and kaggle_key if needed
The kaggle package authenticates when it is first imported, but silently ignores failure. Calling api.authenticate() again means a missing credential fails loudly here, and on Kaggle it picks up the secrets we just copied into the environment.
The API’s list calls return response objects whose payload lives in an attribute, for example competitions_list().competitions:
['Passenger Screening Algorithm Challenge', 'Zillow Prize: Zillow’s Home Value Prediction (Zestimate)', 'Data Science Bowl 2017', 'Vesuvius Challenge - Ink Detection', 'ARC Prize 2026 - ARC-AGI-3', 'ARC Prize 2026 - ARC-AGI-2', 'Google DeepMind - Vibe Code with Gemini 3 Pro in AI Studio ', 'Red‑Teaming Challenge - OpenAI gpt-oss-20b', 'OpenAI to Z Challenge', 'ARC Prize 2026 - Paper Track', 'The Pokémon Company - PTCG AI Battle Challenge Strategy', 'LLM Prompt Recovery', 'Vesuvius Challenge - Surface Detection', 'Google - American Sign Language Fingerspelling Recognition', 'Second Annual Data Science Bowl', 'The Gemma 4 Good Hackathon', 'Measuring Progress Toward AGI - Cognitive Abilities', 'National Data Science Bowl', '2019 Data Science Bowl', 'Feedback Prize - Evaluating Student Writing']
Get a path to data for competition, downloading it if needed
If you pass a list of space separated modules to install, they’ll be installed if running on Kaggle.
Submit file_name to competition, returning the submission response
Once you’ve created a submission file, submit it directly from your script or notebook. E.g:
The response includes a message confirming the submission was created. Note that on Kaggle “code competitions” you must instead submit a notebook through push_notebook.
Get the dict required for a kernel-metadata.json file
{'id': 'jhoward/my-notebook',
'title': 'My notebook',
'code_file': 'my-notebook.ipynb',
'language': 'python',
'kernel_type': 'notebook',
'is_private': True,
'enable_gpu': False,
'enable_internet': True,
'keywords': [],
'dataset_sources': [],
'kernel_sources': [],
'competition_sources': ['competitions/paddy-disease-classification']}
Push notebook file to Kaggle Notebooks
Note that Kaggle recommends that the id match the slug for the title – i.e it should be the same as the title, but lowercase, no punctuation, and spaces replaced with dashes. E.g:
The response returned by Kaggle includes the notebook’s url, and an error string if the push failed.
Does dataset_slug exist on Kaggle?
Because it asks Kaggle directly, this works for any public dataset, not just your own. A dataset you cannot see reports as not existing:
Creates minimal dataset metadata needed to push new dataset to kaggle
The upload=False form only creates the folder and its dataset-metadata.json locally, which is also how we can demonstrate it without creating a real dataset:
Data package template written to: testds/dataset-metadata.json
{'title': 'mytestds',
'id': 'jhoward/mytestds',
'licenses': [{'name': 'CC0-1.0'}]}
get_dataset downloads an existing dataset, along with its metadata file, ready to update and push back:
Downloads an existing dataset and metadata from kaggle
To fill a library dataset with installable files, download the library’s wheels with pip:
Download the whl files for pip_library and store in dataset_path
get_pip_libraries does the same for everything in a requirements.txt file.
Download whl files for a requirements.txt file and store in dataset_path
Once the local folder holds the new files, push_dataset uploads a new version:
Push dataset update to kaggle. Dataset path must contain dataset metadata file
get_local_ds_ver reads the version number from a library’s wheel in a local dataset copy, so the high level functions below can tell whether the Kaggle copy is up to date.
Checks a local copy of kaggle dataset for library version number
For each library, create or update a kaggle dataset with the latest version
def create_requirements_dataset(
req_fpath, # Path to requirements.txt file
lib_path, # Local path to dl/create dataset
title, # Title you want the kaggle dataset named
username, # Your username
retain:list=['dataset-metadata.json'], # Files that should not be removed
version_notes:str='New Update', # Comment associated with this dataset update
):Download everything needed in a requirements.txt file to a dataset and upload to kaggle