Package: kaggle-st-connection
KaggleStConnection DocumentationKaggleStConnectionis a Streamlit connection class that connects to Kaggle API. Better than the defaultKaggle API,KaggleStConnectionautomates 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:KaggleStConnectionKaggleStConnectionDemoYou may access the app atthis link.Package InstallationTo installKaggleStConnectionin your local machine, install the package with the code below in the terminal and you are ready to go.pipinstallkaggle-st-connectionInitializing KaggleStConnectionAfter you have installed theKaggleStConnectionpackage 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 importsfromKaggleAPIConnectionimportKaggleAPIConnectionimportstreamlitasst# Initialize connectionconn=st.connection("kaggle",type=KaggleAPIConnection)# Obtain connection objectcursor=conn.cursor()You can use the connection objectcursorto call some KaggleAPI methods likedataset_list()and many more depending on your use cases.Querying Data From Kaggle DatasetsWe can use thequery()method and specify the Kaggle dataset reference in the format of'[owner_slug]/[dataset_slug]'as the method argument.We can additionally use thefilekeyword 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 reffile='AB_US_2023.csv'# Optional file to open)In this case, we set the parameterfileto'AB_US_2023.csv'so that we will obtain the desired latest data for our sample visualization shown below.Configuring Kaggle API KeyBefore 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 onkaggle.comfrom 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 ofkaggle.json, a file containing your API credentials.To use your API keys in Streamlit, you can either:Go to yourProject Root (~)and create a.kagglefolder and place yourkaggle.jsoninside the folder.Go to yourWorkspace Rootand create a.streamlitfolder and create asecrets.tomlfile, 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 yourkaggle.jsonfile.[NOT RECOMMENDED FOR PUBLIC DEPLOYMENT]Specify thekaggle_usernameandkaggle_keyoptional parameter during the initialization of the connection withst.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 yourkaggle.jsonfile.You can read more about secrets management inStreamlit's secrets management documentation.