connecting-streamlit-to-snowflake

Connect Streamlit apps to Snowflake using st.connection and st.secrets.

Updated Apr 20, 2025
One-click install
npx skills add https://github.com/cathayrisk/Anya --skill connecting-streamlit-to-snowflake-cathayrisk
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: connecting-streamlit-to-snowflake
Source: https://github.com/cathayrisk/Anya/tree/main/skills/developing-with-streamlit/skills/connecting-streamlit-to-snowflake
Command: npx skills add https://github.com/cathayrisk/Anya --skill connecting-streamlit-to-snowflake-cathayrisk

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Streamlit apps need a safe, performant, and maintainable way to connect to Snowflake for querying, caching, writing data, and integrating LLMs without embedding credentials or mismanaging connections.

Core Features & Use Cases

  • Safe connections: Use st.connection to get automatic pooling, caching, and reconnection handling instead of raw connectors.
  • Secrets management: Configure multiple named Snowflake connections via st.secrets to avoid committing credentials and to support prod/staging environments.
  • Querying and writes: Run parameterized queries to prevent SQL injection, cache results with TTL, and perform session-based writes for data ingestion.
  • Advanced scenarios: Support caller's rights for row-level security and streaming LLM responses via Snowflake Cortex for chat-style UIs.

Quick Start

Use st.connection to obtain a Snowflake connection, run a parameterized query to fetch results, and display the returned dataframe in your Streamlit app.

Frequently Asked Questions about connecting-streamlit-to-snowflake

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I securely connect a Streamlit app to Snowflake?

To securely connect Streamlit to Snowflake, use st.connection for automatic connection pooling and manage credentials via st.secrets to avoid hardcoding sensitive information in your application code.

Can I manage multiple Snowflake connections in Streamlit for different environments?

Yes, you can manage multiple Snowflake connections in Streamlit by configuring named connections through st.secrets, enabling separate setups for production and staging environments without exposing credentials.

How do I prevent SQL injection when querying Snowflake from Streamlit?

Prevent SQL injection when querying Snowflake from Streamlit by using parameterized queries, ensuring user-supplied values are safely handled and separated from the SQL command structure.

What is the best way to cache Snowflake query results in a Streamlit app?

The best way to cache Snowflake query results in Streamlit is by using st.connection, which provides built-in caching and reconnection handling to optimize data retrieval performance with TTL.

Does Streamlit support streaming LLM responses from Snowflake Cortex?

Yes, Streamlit supports streaming LLM responses from Snowflake Cortex, allowing you to build interactive chat-style user interfaces that fetch and display generative AI outputs directly.

Can I perform session-based write operations to Snowflake using Streamlit?

Yes, you can perform session-based write operations to Snowflake using Streamlit, enabling data ingestion and row-level security access through caller's rights within your interactive data apps.