Hi @Khasim_1,
It looks like the template placeholders made it into the post, so I'm not sure exactly where you're stuck. In case it helps, here's a minimal Streamlit app that reads a Unity Catalog table through a SQL warehouse. That covers the three things people usually get stuck on: app.yaml, authentication and UC permissions.
1. Files
my-app/
app.py
app.yaml
requirements.txt
app.yaml (the warehouse ID comes from an app resource with the key sql-warehouse):
command: ['streamlit', 'run', 'app.py']
env:
- name: 'DATABRICKS_WAREHOUSE_ID'
valueFrom: 'sql-warehouse'
- name: 'STREAMLIT_GATHER_USAGE_STATS'
value: 'false'requirements.txt:
databricks-sdk
databricks-sql-connector
pandas
app.py:
import os
import streamlit as st
from databricks import sql
from databricks.sdk.core import Config
cfg = Config() # picks up the app's own service principal credentials
@st.cache_resource
def get_connection():
return sql.connect(
server_hostname=cfg.host,
http_path=f"/sql/1.0/warehouses/{os.getenv('DATABRICKS_WAREHOUSE_ID')}",
credentials_provider=lambda: cfg.authenticate,
)
def run_query(query: str):
with get_connection().cursor() as cursor:
cursor.execute(query)
return cursor.fetchall_arrow().to_pandas()
st.title("Quick table viewer")
df = run_query("SELECT * FROM samples.nyctaxi.trips LIMIT 100")
st.dataframe(df)2. Add the warehouse as a resource
When you create or edit the app, add a SQL warehouse resource, give it the key sql-warehouse and the Can use permission. That's what fills in DATABRICKS_WAREHOUSE_ID, and it gives the app's service principal access to the warehouse.
3. Grant Unity Catalog access to the app's service principal
By default the app queries as its own service principal, not as you. That's the most common reason an app works in testing and then hits "permission denied". You can find the principal on the app's Authorization tab. Use its application ID in the grants:
GRANT USE CATALOG ON CATALOG main TO `<app-sp-application-id>`;
GRANT USE SCHEMA ON SCHEMA main.sales TO `<app-sp-application-id>`;
GRANT SELECT ON TABLE main.sales.orders TO `<app-sp-application-id>`;
If you need each user to see only what they're allowed to see, look at user authorization (on-behalf-of-user) in the Apps docs instead.
4. Deploy
databricks apps create my-app
databricks sync ./my-app /Workspace/Users/<you>/my-app
databricks apps deploy my-app --source-code-path /Workspace/Users/<you>/my-app
If it doesn't start, check the Logs tab on the app page first. A missing package in requirements.txt or a wrong command in app.yaml shows up there right away.
If you share your framework, what you're building and the actual error, I'm happy to look at the specific blocker.
Docs: