Example - Accessing Snowflake data from Streamlit in SnowflakeΒΆ

Attention

This feature is available to accounts in AWS and Microsoft Azure commercial 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
    
    Copy
  2. Import get_active_session from the Snowpark library:

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

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

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

    data = session.sql(sql).collect()
    
    Copy
  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.