# Connecting Streamlit To Snowflake

Connecting Streamlit apps to Snowflake.

- Repository: https://github.com/iusztinpaul/designing-real-world-ai-agents-workshop (521 stars)
- Category: Data and ML
- License: Apache-2.0
- Last updated: 2026-06-03
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add iusztinpaul/designing-real-world-ai-agents-workshop --skill connecting-streamlit-to-snowflake -g -a claude-code -y`
Codex: `npx skills add iusztinpaul/designing-real-world-ai-agents-workshop --skill connecting-streamlit-to-snowflake -g -a codex -y`
Cursor: `npx skills add iusztinpaul/designing-real-world-ai-agents-workshop --skill connecting-streamlit-to-snowflake -g -a cursor -y`
Gemini CLI: `npx skills add iusztinpaul/designing-real-world-ai-agents-workshop --skill connecting-streamlit-to-snowflake -g -a gemini-cli -y`

## Description

Connecting Streamlit apps to Snowflake. Use when setting up database connections, managing secrets, or querying Snowflake from a Streamlit app.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Streamlit Snowflake connection

Connect your Streamlit app to Snowflake the right way.

## Use st.connection

Always use `st.connection("snowflake")` instead of raw connectors.

```python
import streamlit as st

conn = st.connection("snowflake")

# Query data
df = conn.query("SELECT * FROM my_table LIMIT 100")
st.dataframe(df)
```

**Why st.connection:**
- Automatic connection pooling
- Built-in caching
- Handles reconnection
- Works with st.secrets

## Caller's rights connection (Streamlit 1.53+)

For apps running in Snowflake, use caller's rights to run queries with the viewer's permissions instead of the app owner's:

```python
conn = st.connection("snowflake", type="snowflake-callers-rights")
```

This is useful when:
- Different users should see different data based on their Snowflake roles
- You want row-level security to apply based on the viewer
- You don't want the app to have elevated permissions

## Cached queries

Use the built-in `ttl` parameter to cache query results:

```python
from datetime import timedelta

conn = st.connection("snowflake")

# Cache for 10 minutes
df = conn.query("SELECT * FROM metrics", ttl=timedelta(minutes=10))

# Cache for 1 hour
df = conn.query("SELECT * FROM reference_data", ttl=3600)
```

## Configure with st.secrets

Store credentials in `.streamlit/secrets.toml` (never commit this file).

**CRITICAL**: Derive the `account` and `host` values from the user's Snowflake CLI connection config. Run `snow connection list` and use the exact values. A wrong `account` will redirect to the wrong login page.

```toml
# .streamlit/secrets.toml
[connections.snowflake]
account = "ORGNAME-ACCTNAME"            # from `snow connection list`
host = "myaccount.snowflakecomputing.com"  # from `snow connection list` (include if present)
user = "your_user"
authenticator = "externalbrowser"
warehouse = "your_warehouse"
database = "your_database"
schema = "your_schema"
```

Add to `.gitignore`:
```
.streamlit/secrets.toml
```

The rest: https://github.com/iusztinpaul/designing-real-world-ai-agents-workshop/blob/HEAD/.agents/skills/developing-with-streamlit/skills/connecting-streamlit-to-snowflake/SKILL.md
