Skip to main content

8  Kaggle datasets

Kaggle generates Croissant metadata for each public dataset it hosts, the document a dataset page exports through “Download”, then “Export metadata as Croissant”. croissant reads this metadata, reads the records it describes from the dataset’s archive, and reads a Croissant file that a dataset stores among its files. A Kaggle API token gives access to private datasets.

The examples on this page require network access and are not executed when this book is built.

library(croissant)

8.1 Two Croissant documents

A Kaggle dataset can have two Croissant documents, which describe different files and hold different metadata.

  • Kaggle-generated metadata. Kaggle generates Croissant 1.0 metadata from the dataset’s files and its settings on Kaggle. It describes the dataset’s current version: its zip archive, with the archive’s MD5, and the files within the archive whose format Kaggle recognizes. read_croissant_kaggle() reads it.
  • A dataset’s own metadata. A Croissant file that the dataset’s authors write and upload with the data, such as croissant.json. It is an ordinary file of the dataset: Kaggle neither reads nor changes it. read_croissant_kaggle() reads it when given its path as file.

Kaggle generates a record set with one field per column for CSV files, with data types such as sc:Text, sc:Integer, sc:Float, sc:Date, and sc:URL. It generates no record set for Parquet files, image files, or signal files, which it lists as file sets (Croissant Baker comparison, arXiv 2605.15079, Table 7). The column descriptions that dataset-metadata.json gives for the Parquet files of rtemisorg/rtemis-demo do not appear in its generated metadata.

On 2026-11-14, the two documents of rtemisorg/rtemis-demo, which holds two Parquet files and the croissant.json that describes them, differed as follows.

Kaggle-generated croissant.json in the dataset
Croissant version 1.0 1.1
Files The version’s zip archive, and a FileSet of the *.json files in it The two Parquet files, each with its size and SHA-256
Record sets None One per table, with an enumeration record set listing the levels of each categorical column
Field descriptions None As written
name, alternateName, description, license, keywords, creator From the dataset’s settings on Kaggle; license as Kaggle names it, such as CC0: Public Domain As written
version The Kaggle version number, as a JSON number As written
citeAs, datePublished Absent As written

The Hugging Face and Kaggle article reads the same dataset from both sites and compares the three documents.

8.2 Dataset names

A Kaggle dataset is named as <owner>/<slug>, or by the URL of its page, https://www.kaggle.com/datasets/<owner>/<slug>, which may carry further path segments, a query, or a fragment, as a URL copied from the browser does. Any other value raises an error of class rtemis_value_error.

read_croissant_kaggle("yasserh/titanic-dataset")
read_croissant_kaggle("https://www.kaggle.com/datasets/yasserh/titanic-dataset/data")

8.3 Reading the generated metadata

read_croissant_kaggle(dataset) downloads https://www.kaggle.com/datasets/<owner>/<slug>/croissant/download and reads it with read_croissant().

x <- read_croissant_kaggle("yasserh/titanic-dataset")
x
#> <Croissant>
#>   Titanic Dataset
#>   Record sets (1)
#>     Titanic-Dataset.csv  12 fields: PassengerId, Survived, Pclass, and 9 more
#>   Files (2)
#>     archive.zip                     application/zip, 22.035 KB, https://www.k...
#>     Titanic-Dataset.csv_fileobject  application/vnd.ms-excel, Titanic-Dataset...
#>   Metadata
#>     version           Croissant 1.0
#>     dataset version   1.0.0
#>     license           CC0: Public Domain
#>     creator           M Yasser H
#>     publisher         Kaggle
#>     ...
validate_croissant(x)
#> <CroissantIssues>
#>   0 errors, 1 warning
#>   Warnings
#>   - [Croissant(Titanic Dataset)] The recommended property citeAs is absent.

Kaggle writes the dataset version as a JSON number, which read_croissant() reads as mlcroissant does: 1 as "1.0.0". It writes the archive’s MD5 in base64, which read_record_set() accepts as it accepts hexadecimal.

Kaggle serves the generated metadata of public datasets. For a dataset that does not exist, is private, or has no generated metadata, read_croissant_kaggle() raises an error of class croissant_download_error that names the dataset page. The metadata describes the dataset’s current version, the one version for which Kaggle serves metadata.

8.4 Reading records

Each data file of the generated metadata is a FileObject contained in the version’s zip archive, https://www.kaggle.com/api/v1/datasets/download/<owner>/<slug>?datasetVersionNumber=<n>. read_record_set() downloads the archive, checks its MD5, extracts it into the cache directory, and reads the file the record set names. A later read reuses the cached archive and its extraction. n_max limits the records returned, not the download: the whole archive is downloaded.

dat <- read_record_set(x, "Titanic-Dataset.csv", n_max = 5)
#> ▶ Reading record set Titanic-Dataset.csv of Titanic Dataset...
#> ℹ Downloading https://www.kaggle.com/api/v1/datasets/download/yasserh/titanic-dataset?datasetVersionNumber=1
#> ℹ Extracting titanic-dataset
#> Read in 5 x 12 (n_max reached) in 0.4 s
dat[, 1:3]
#>    PassengerId Survived Pclass
#>         <char>    <int>  <int>
#> 1:           1        0      3
#> 2:           2        1      1
#> 3:           3        1      3
#> 4:           4        1      1
#> 5:           5        0      3

Each column is cast by its field’s data type, so the types are those Kaggle generates: PassengerId is sc:Text and reads as character.

8.4.1 CSV files as Kaggle describes them

Kaggle’s generated metadata describes CSV files in forms that read_record_set() reads as follows (reading records).

  • Encoding format. Kaggle declares many CSV files as application/vnd.ms-excel or application/octet-stream. A file none of whose encoding formats names a format read_record_set() reads is read by the format its extension names, here .csv.
  • Empty header. A CSV column whose header is empty, such as an index column written by pandas, is the field’s column "".
  • Dates. Kaggle types date columns as sc:Date. A column holding text outside ISO 8601, such as September 25, 2021, stays character, with a warning that names the field.
  • Quoting. A CSV file that data.table::fread() stops reading early, at a row whose number of fields differs from the header’s, raises an error of class croissant_format_error, so that no records are dropped without notice.

8.5 Reading a dataset’s metadata file

read_croissant_kaggle(dataset, file) reads the Croissant file stored at the path file in the dataset, from https://www.kaggle.com/api/v1/datasets/download/<owner>/<slug>/<file>. Its relative contentUrls name files of the same dataset, which read_record_set() downloads from the Kaggle API, one file at a time, and verifies against the sha256 or md5 of the metadata.

x <- read_croissant_kaggle("rtemisorg/rtemis-demo", file = "croissant.json")
#> ▶ Reading https://www.kaggle.com/api/v1/datasets/download/rtemisorg/rtemis-demo/croissant.json...
#> Read demo: Croissant 1.1, 2 record sets, 21 enumerations, 2 files
names(record_sets(x))
#> [1] "regression"     "classification"
dat <- read_record_set(x, "classification")
#> ▶ Reading record set classification of demo...
#> ℹ Downloading https://www.kaggle.com/api/v1/datasets/download/rtemisorg/rtemis-demo/data%2Fclassification.parquet
#> Read in 1,000 x 101 in 1.1 s
levels(dat[["class"]])
#> [1] "no"  "yes"

The Kaggle API serves a file in a folder only when the / of its path is written %2F, as in data%2Fclassification.parquet; croissant encodes the path. The object’s base is the dataset’s download URL, followed by the encoded folder of the metadata file when the file is in a folder:

x@base
#> [1] "https://www.kaggle.com/api/v1/datasets/download/rtemisorg/rtemis-demo"

A stored Croissant file is the way to describe a Parquet dataset on Kaggle, for which Kaggle generates no record set. The same croissant.json uploaded to Kaggle and to the Hugging Face Hub reads into objects that write_croissant() writes identically, and its record sets read the same records from either site.

8.6 Private datasets

A private dataset requires a Kaggle API token with access to it, created at kaggle.com/settings/api. croissant resolves the token as the Kaggle command-line tool and kagglehub resolve it:

  1. the token argument of read_croissant_kaggle(), or the kaggle_token argument of read_record_set();
  2. the environment variable KAGGLE_API_TOKEN, holding the token or the path of a file that holds it;
  3. the file .kaggle/access_token, or .kaggle/access_token.txt, in the directory that HOME names, or USERPROFILE on Windows.

A token set up for the Kaggle command-line tool therefore works without further configuration.

Sys.setenv(KAGGLE_API_TOKEN = "<token>")
x <- read_croissant_kaggle("<owner>/<private-dataset>", file = "croissant.json")
dat <- read_record_set(x, "<record set>")

The token is sent as an Authorization: Bearer header to the Kaggle API, https://www.kaggle.com/api/, and to no other host; it does not appear in any message or condition. When the Kaggle API redirects a download to another host, such as Google Cloud Storage, the header is not sent with the redirected request. A stored Croissant file of a private dataset read without a token raises an error of class croissant_download_error that lists the token’s sources. Kaggle serves its generated metadata for public datasets only; a token gives no access to that of a private dataset.

© 2026 E.D. Gennatas