Example - Accessing Snowflake data from Streamlit in Snowflake¶
This topic describes how to access Snowflake data from a Streamlit app in Streamlit in Snowflake.
Streamlit in Snowflake provides a convenience session that allows a Streamlit app to connect to Snowflake without having to provide Snowflake credentials when using this session.
To access Snowflake data from a Streamlit app:
Import the Streamlit library:
import streamlit as st
Import
get_active_session
from the Snowpark library:from snowflake.snowpark.context import get_active_session
Create a session:
session = get_active_session()
Define a SQL query:
sql = f"select * from snowflake_sample_data.tpch_sf1.lineitem limit 20"
Run the query and convert the result to a Pandas dataframe:
data = session.sql(sql).collect()
Add Streamlit features to your app to display the results of your query.
See Get Started for information on using Streamlit. Also, see Unsupported Streamlit features.