from cjm_kaggle_utils.core import save_kaggle_creds
cjm-kaggle-utils
Some utility functions for working with the Kaggle API.
Install
pip install cjm_kaggle_utils
How to use
save_kaggle_creds
= "name"
username = "12345"
key =False) save_kaggle_creds(username, key, overwrite
Credentials already present. Set `overwrite=True` to replace them.
dl_kaggle
from cjm_kaggle_utils.core import dl_kaggle
from pathlib import Path
# Get the path to the directory where datasets are stored
= Path("./Datasets/")
dataset_dir =True, exist_ok=True)
dataset_dir.mkdir(parentsprint(f"Dataset Directory: {dataset_dir}")
# Create the path to the data directory
= dataset_dir/'../Archive'
archive_dir =True, exist_ok=True)
archive_dir.mkdir(parentsprint(f"Archive Directory: {archive_dir}")
Dataset Directory: Datasets
Archive Directory: Datasets/../Archive
# Set the name of the dataset
= 'style-image-samples'
dataset_name
# Construct the Kaggle dataset name by combining the username and dataset name
= f'innominate817/{dataset_name}' kaggle_dataset
# Create the path to the zip file that contains the dataset
= Path(f'{archive_dir}/{dataset_name}.zip')
archive_path print(f"Archive Path: {archive_path}")
# Create the path to the directory where the dataset will be extracted
= Path(f'{dataset_dir}/{dataset_name}')
dataset_path print(f"Dataset Path: {dataset_path}")
Archive Path: Datasets/../Archive/style-image-samples.zip
Dataset Path: Datasets/style-image-samples
dl_kaggle(kaggle_dataset, archive_path, dataset_path)
Downloading style-image-samples.zip to Datasets/../Archive
100%|██████████████████████████████████████████████████████████████████████████████████████████████| 16.2M/16.2M [00:00<00:00, 44.0MB/s]
!ls {dataset_path}
images