Skip to main content

st.connection implementation for Kaggle Public API

Project description

KaggleStConnection Documentation

KaggleStConnection is a Streamlit connection class that connects to Kaggle API. Better than the default Kaggle API, KaggleStConnection automates the reading of a specific data file from your desired dataset found on Kaggle.

You can view the source GitHub repository for the connection class and the demo app in the links below:

You may access the app at this link.

Screenshot 2023-12-08 at 11 26 05 AM

Package Installation

To install KaggleStConnection in your local machine, install the package with the code below in the terminal and you are ready to go.

pip install kaggle-st-connection

Initializing KaggleStConnection

After you have installed the KaggleStConnection package in the step above, you can start to initialize a connection to the Kaggle API and obtain a connection object with the following code.

# Package imports
from KaggleAPIConnection import KaggleAPIConnection
import streamlit as st

# Initialize connection
conn = st.connection("kaggle", type=KaggleAPIConnection)

# Obtain connection object
cursor = conn.cursor()

You can use the connection object cursor to call some KaggleAPI methods like dataset_list() and many more depending on your use cases.

Querying Data From Kaggle Datasets

We can use the query() method and specify the Kaggle dataset reference in the format of '[owner_slug]/[dataset_slug]' as the method argument.

We can additionally use the file keyword argument to specify the dataset file to query from. By default, the first file in the dataset will be queried.

# Using the previous initialized connection object `conn`
data = conn.query(
    'kritikseth/us-airbnb-open-data',   # Dataset ref
    file='AB_US_2023.csv'               # Optional file to open
)

In this case, we set the parameter file to 'AB_US_2023.csv' so that we will obtain the desired latest data for our sample visualization shown below.

Configuring Kaggle API Key

Before the above code can work, we will need to specify the API key during the initialization of the connection. The following quote the steps to obtain your API key on kaggle.com from the Kaggle Documentation.

🗨 Kaggle's Public API Documentation (Read Here)
In order to use Kaggle's public API, you must first authenticate using an API token. Go to the 'Account' tab of your user profile and select 'Create New Token'. This will trigger the download of kaggle.json, a file containing your API credentials.

To use your API keys in Streamlit, you can either:

  • Go to your Project Root (~) and create a .kaggle folder and place your kaggle.json inside the folder.
  • Go to your Workspace Root and create a .streamlit folder and create a secrets.toml file, then enter the following in the file:
    [connections.kaggle]
    kaggle_username='<USERNAME>'
    kaggle_key='<API_KEY>'
    
    Replace the <USERNAME> and the <API_KEY> with that in your kaggle.json file.
  • [NOT RECOMMENDED FOR PUBLIC DEPLOYMENT] Specify the kaggle_username and kaggle_key optional parameter during the initialization of the connection with st.connection. An example of this use case is shown below:
    conn = st.connection(
        'kaggle', 
        type=KaggleAPIConnection,
        kaggle_username='<USERNAME>',
        kaggle_key='<API_KEY>'
    )
    
    Similarly to the previous bullet, replace the <USERNAME> and the <API_KEY> with that in your kaggle.json file.

You can read more about secrets management in Streamlit's secrets management documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kaggle-st-connection-1.3.3.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

kaggle_st_connection-1.3.3-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file kaggle-st-connection-1.3.3.tar.gz.

File metadata

  • Download URL: kaggle-st-connection-1.3.3.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for kaggle-st-connection-1.3.3.tar.gz
Algorithm Hash digest
SHA256 e24f534c1bdfb4dde92c4b98a872dd4f99b84236e772e87297588a1b9c2223f1
MD5 50d5dbcb502690225cf508eb7b28147e
BLAKE2b-256 6ee8a8a7032a8ef7bf5a3d3a9f92a909899669fdc4058457d3f263695bf7504d

See more details on using hashes here.

File details

Details for the file kaggle_st_connection-1.3.3-py3-none-any.whl.

File metadata

File hashes

Hashes for kaggle_st_connection-1.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 644a0784c85c649bcaaed4cf39dc3a1039467066edbdffe9a67e02b94b29c3b5
MD5 fba3fa33f0e24209154ece6fd8d66618
BLAKE2b-256 b2a0e37c5b02f738e10bf7938f79206a5b363062df1626e60777b10a34bedc31

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page