I’m trying to connect to our snowflake instance and print rows from a table in Streamlit. When I run the code locally the query executes and I can view the results in rows. However, the main Streamlit window shows a ModuleNotFoundError.
streamlit_app.py
import streamlit as st
import snowflake.connector
Initialize connection.
Uses st.experimental_singleton to only run once.
@st.experimental_singleton
def init_connection():
return snowflake.connector.connect(user = “XXX”,
authenticator=‘externalbrowser’,
account = “XXX”,
warehouse = “XXX”,
database = “XXX”,
schema = “XXX”)
conn = init_connection()
Perform query.
Uses st.experimental_memo to only rerun when the query changes or after 10 min.
@st.experimental_memo(ttl=600)
def run_query(query):
with conn.cursor() as cur:
cur.execute(query)
return cur.fetchall()
rows = run_query(“SELECT * from XXX;”)
Print results.
for row in rows:
st.write(f"{row[0]} has a :{row[1]}:")