Skip to main content

A Python library that simplifies Keboola SAPI integration in Streamlit apps.

Project description

Alt text

KeboolaStreamlit

KeboolaStreamlit simplifies the use of Keboola Storage API within Streamlit apps, providing easy-to-use functions for authentication, data retrieval, event logging, and data loading.

Installation

To install:

pip install keboola-streamlit

If you are using streamlit<=1.36.0, please use version 0.0.5 of the keboola-streamlit package.

Usage

Import and Initialization

Create an instance of the KeboolaStreamlit class, and initialize it with the required parameters from Streamlit secrets:

import streamlit as st
from keboola_streamlit import KeboolaStreamlit

URL = st.secrets["KEBOOLA_URL"]
TOKEN = st.secrets["STORAGE_API_TOKEN"]

keboola = KeboolaStreamlit(root_url=URL, token=TOKEN)

Authentication and Authorization

If only selected roles can access the app, make sure the user is authorized by:

ROLE_ID = st.secrets["REQUIRED_ROLE_ID"]

keboola.auth_check(required_role_id=ROLE_ID)

Add a logout button to your app:

keboola.logout_button(sidebar=True, use_container_width=True)

💡 You can find more about authorization settings in Keboola here.

Reading Data from Keboola Storage

Read data from a Keboola Storage table and return it as a Pandas DataFrame:

df = keboola.read_table(table_id='YOUR_TABLE_ID')

💡 Wrap the function and use the st.cache_data decorator to prevent your data from being read every time you interact with the app. Learn more about caching here.

Writing Data to Keboola Storage

Write data from a Pandas DataFrame to a Keboola Storage table:

keboola.write_table(table_id='YOUR_TABLE_ID', df=your_dataframe, is_incremental=False)

Creating Events

Create an event in Keboola Storage to log activities:

keboola.create_event(message='Streamlit App Create Event', event_type='keboola_data_app_create_event')

Table Selection

Add a table selection interface in your app:

df = keboola.add_table_selection(sidebar=True)

Snowflake Integration

Creating a Snowflake Session

To interact with Snowflake, first create a session using your Streamlit secrets. Ensure that the following secrets are set in your Streamlit configuration:

  • SNOWFLAKE_USER
  • SNOWFLAKE_PASSWORD
  • SNOWFLAKE_ACCOUNT
  • SNOWFLAKE_ROLE
  • SNOWFLAKE_WAREHOUSE
  • SNOWFLAKE_DATABASE
  • SNOWFLAKE_SCHEMA

Then, create the session as follows:

st.session_state['snowflake_session'] = keboola.snowflake_create_session_object()

Reading Data from Snowflake

Load a table from Snowflake into a Pandas DataFrame:

df_snowflake = keboola.snowflake_read_table(session=st.session_state['snowflake_session'], table_id='YOUR_SNOWFLAKE_TABLE_ID')

Executing a Snowflake Query

Execute a SQL query on Snowflake and optionally return the results as a DataFrame:

query = "SELECT * FROM YOUR_SNOWFLAKE_TABLE"
df_query_result = keboola.snowflake_execute_query(session=st.session_state['snowflake_session'], query=query, return_df=True)

Writing Data to Snowflake

Write a Pandas DataFrame to a Snowflake table:

keboola.snowflake_write_table(session=st.session_state['snowflake_session'], df=your_dataframe, table_id='YOUR_SNOWFLAKE_TABLE_ID')

License

This project is licensed under the MIT License. See the LICENSE file for more details.

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

keboola_streamlit-0.1.2.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

keboola_streamlit-0.1.2-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file keboola_streamlit-0.1.2.tar.gz.

File metadata

  • Download URL: keboola_streamlit-0.1.2.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.18

File hashes

Hashes for keboola_streamlit-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d26deaea0ef140edf82dca6a157a95f17d0f172538e7639b8b161a6221e658eb
MD5 6f23efcb4ba31a6b81ce9a14512bb54e
BLAKE2b-256 cad00f2c1e9d9b69e1eeddffe1f25f9bfdd9f712e78f8c1becf2cb3c6d818ba8

See more details on using hashes here.

File details

Details for the file keboola_streamlit-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for keboola_streamlit-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ef6b2909b404fb5fbe5fc9a5506763c937dd4f13e4c28f1b691fe9bf129f3003
MD5 e0b5114f833229566b0cf422e4e37da5
BLAKE2b-256 918a940927b18a1e83ee463d673abb9c3cfd40032db6be1cc202198b8cf06f8e

See more details on using hashes here.

Supported by

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