How do I access data from Snowflake in Streamlit?

469 viewsStreamlit

How do I access data from Snowflake in Streamlit?

Daniel Steinhold Asked question September 14, 2023

To access data from Snowflake in Streamlit, you can use the following steps:

  1. Install the following Python libraries:

    • snowflake-connector-python
    • streamlit
  2. Create a file called and add the following code:

import snowflake.connector as sf
import streamlit as st

# Get the user credentials from the secrets file
with open(".streamlit/secrets.toml") as f:
    secret_data =
    credentials = toml.load(secret_data)

# Connect to Snowflake
conn = sf.connect(

# Run a query
df = conn.execute("SELECT * FROM my_table")

# Display the results in a Streamlit table
  1. Save the file and run it in your terminal.

This code will first get the user credentials from a secrets file. Then, it will connect to Snowflake using those credentials. Finally, it will run a query and display the results in a Streamlit table.

Here are some additional resources that you may find helpful:

  • Streamlit documentation on connecting to databases:
  • Snowflake documentation on connecting to Python:
Daniel Steinhold Changed status to publish September 14, 2023
Feedback on Q&A