> ## Content Index
> Fetch the complete content index at: https://www.daanalytics.nl/llms.txt
> Use this file to discover other available public pages before exploring further.

# Loading Kaggle Data into Snowflake with the Kaggle API
- URL: https://www.daanalytics.nl/from-kaggle-to-snowflake/
- Published: 2022-03-20T15:21:45.000Z
- Updated: 2026-09-06T14:43:23.000Z
- Author: Daan Bakboord
- Tags: Data Engineering, Snowflake, Kaggle, Python, API, Data Ingestion, #Historical technical article

💡

Originally published in 2022\. Snowflake, its user interface and the referenced integrations may have changed since publication. This article is retained for historical and educational context; verify implementation details against the current official documentation.

If you want to load [Kaggle](https://www.kaggle.com/rohanrao/formula-1-world-championship-1950-2020?ref=daanalytics.nl) data into Snowflake without manually downloading datasets, the [Kaggle API](https://github.com/Kaggle/kaggle-api?ref=daanalytics.nl) can automate the first part of the workflow.

In this example, I use the Kaggle API to authenticate, download and unzip a dataset before continuing with the process of loading the CSV data into Snowflake. This example is different than the example in a previous [blogpost](https://daanalytics.nl/from-csv-to-snowflake/?ref=daanalytics.nl) I showed how to load .csv-files into Snowflake

## How does the Kaggle-to-Snowflake workflow work?

The workflow in this example consists of two parts. First, the Kaggle API is used to authenticate and download the dataset. The downloaded files are then unzipped and prepared for the existing CSV-to-Snowflake loading process.

In short:

1. Authenticate with the Kaggle API
2. Download the Kaggle dataset
3. Unzip the downloaded files
4. Read the CSV data
5. Create the required Snowflake objects
6. Load the data into Snowflake

#### Install Kaggle

I have used Kaggle in a Anaconda environment. Therefore I have a separate environment in which I installed [Kaggle](https://anaconda.org/conda-forge/kaggle?ref=daanalytics.nl).

#### Kaggle API key

First we have to create a Kaggle API key which is necessary to connect to Kaggle. If you have a Kaggle account, you can create new API Token from you account settings (https://www.kaggle.com/<user\_name>/account).

![](https://www.daanalytics.nl/content/images/2022/03/blog-Create-Kaggle-API-Key-2.webp)

##### Standard implementation

Clicking the button above generates a ***kaggle.json***\-file. This file needs to be stored in a folder called ***.kaggle*** in your home directory. The ***kaggle.json***\-file has the following structure:

[Bekijk code op GitHub Gist](https://gist.github.com/daanalytics/ab33de6ecb71ca90da6e344aff078eee?ref=daanalytics.nl)

In the Python-script you can use the OS environment variables directly to authenticate, like presented below:

[Bekijk code op GitHub Gist](https://gist.github.com/daanalytics/c5dacd3a53bde9b8f766c8c764ecdf5f?ref=daanalytics.nl)

##### Customised example

For this example, I was curious whether I could include the ***kaggle.json*** content to the [Credentials](https://github.com/daanalytics/Snowflake/blob/master/python/SF%5Fcred.json?ref=daanalytics.nl)\-file I used in my previous example.

[Bekijk code op GitHub Gist](https://gist.github.com/daanalytics/180de7df4e19902e2f15d664eda0b794?ref=daanalytics.nl)

Authentication in this customised example goes hand in hand with the authentication to Snowflake. The same [Credentials](https://github.com/daanalytics/Snowflake/blob/master/python/SF%5Fcred.json?ref=daanalytics.nl)\-file is referenced for both Snowflake as well as Kagggle:

[Bekijk code op GitHub Gist](https://gist.github.com/daanalytics/eee28e16f5dce688f9190ad58e6b7a7b?ref=daanalytics.nl)

#### Download from Kaggle

Next step is downloading files from Kaggle. For this we reference the [Kaggle API](https://github.com/Kaggle/kaggle-api?ref=daanalytics.nl), specifically; the [dataset\_download\_files()](https://github.com/Kaggle/kaggle-api/blob/master/kaggle/api/kaggle%5Fapi%5Fextended.py?ref=daanalytics.nl#L1195) method

[Bekijk code op GitHub Gist](https://gist.github.com/daanalytics/b9069dd4b917a4e643a71ea3dcdb8956?ref=daanalytics.nl)

#### Unzip records

Data from Kaggle is downloaded in .zip-format. You can unzip the files from within the [Kaggle API](https://github.com/Kaggle/kaggle-api?ref=daanalytics.nl); 'unzip=True'.

An alternative is to unzip the files via the statement below:

[Bekijk code op GitHub Gist](https://gist.github.com/daanalytics/045ff5f4ab297a805f4c30978aa3c382?ref=daanalytics.nl)

#### Continuing

The remainder of is similar to the previous post; [From .csv to Snowflake](https://daanalytics.nl/from-csv-to-snowflake/?ref=daanalytics.nl).

- Reading .csv Data
- Creating Snowflake objects
- Loading Data into Snowflake

Find the code for this blogpost on [Github](https://github.com/daanalytics/Snowflake/blob/master/python/F1DemoConnectKaggle.py?ref=daanalytics.nl).

Thanks for reading and till next time.

[Daan Bakboord – DaAnalytics](https://www.linkedin.com/in/daanbakboord?ref=daanalytics.nl)