Example - Accessing Snowflake data from Streamlit in Snowflake


This feature is available to accounts in AWS, Microsoft Azure, and GCP regions. AWS PrivateLink and Azure Private Link are not supported.

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:

  1. Import the Streamlit library:

    import streamlit as st
  2. Import get_active_session from the Snowpark library:

    from snowflake.snowpark.context import get_active_session
  3. Create a session:

    session = get_active_session()
  4. Define a SQL query:

    sql = f"select * from snowflake_sample_data.tpch_sf1.lineitem limit 20"
  5. Run the query and convert the result to a Pandas dataframe:

    data = session.sql(sql).to_pandas()
  6. 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.