Tech With Galvan
Back to Articles
DevelopmentJul 19, 2026 • 5 min read

Streamlit + Supabase: Add a Real Database to Your App

Connect Streamlit to Supabase — Postgres, auth, storage, and real-time. Build a full data app without managing a backend.

Galvan
Galvan

Founder & Creator

Introduction

Streamlit apps are great — until you need persistent data. SQLite works for prototypes but breaks on Streamlit Cloud (ephemeral filesystem). The fix: Supabase — a hosted Postgres with auth, storage, and real-time, all accessible from Python via a simple client.

This post connects Streamlit to Supabase for a real CRUD app.

What is Supabase?

Supabase is “open-source Firebase”: a managed Postgres database with:

  • Database — Postgres with row-level security (RLS)
  • Auth — email/password, OAuth, magic links
  • Storage — file uploads (images, PDFs)
  • Realtime — subscribe to DB changes
  • Edge functions — serverless (Deno)

Free tier: 500MB DB, 1GB storage, 50k monthly active users.

Setup

pip install supabase streamlit

Create a Supabase project at supabase.com, then grab your URL and anon key from Settings → API. Store in .env or Streamlit secrets.

Step 1: Create a table

In the Supabase SQL editor:

create table notes (
    id bigint generated by default as identity primary key,
    title text not null,
    body text,
    created_at timestamptz default now()
);

-- Enable RLS
alter table notes enable row level security;

-- Allow public read (for demo; tighten in production)
create policy "public read" on notes for select using (true);
create policy "public insert" on notes for insert with check (true);

Step 2: Connect from Streamlit

import streamlit as st
from supabase import create_client

url = st.secrets["SUPABASE_URL"]
key = st.secrets["SUPABASE_KEY"]
supabase = create_client(url, key)

Store secrets in .streamlit/secrets.toml:

SUPABASE_URL = "https://xxxxx.supabase.co"
SUPABASE_KEY = "eyJhbGciOi..."

Step 3: CRUD operations

# Create
def add_note(title, body):
    supabase.table("notes").insert({"title": title, "body": body}).execute()

# Read
def get_notes():
    res = supabase.table("notes").select("*").order("created_at", desc=True).execute()
    return res.data

# Update
def update_note(note_id, title, body):
    supabase.table("notes").update({"title": title, "body": body}).eq("id", note_id).execute()

# Delete
def delete_note(note_id):
    supabase.table("notes").delete().eq("id", note_id).execute()

Step 4: Full Streamlit app

import streamlit as st
from supabase import create_client

supabase = create_client(st.secrets["SUPABASE_URL"], st.secrets["SUPABASE_KEY"])

st.title("📝 Notes (Supabase-backed)")

# Add
with st.form("new", clear_on_submit=True):
    title = st.text_input("Title")
    body = st.text_area("Body")
    if st.form_submit_button("Add") and title:
        supabase.table("notes").insert({"title": title, "body": body}).execute()
        st.rerun()

# List
notes = supabase.table("notes").select("*").order("created_at", desc=True).execute().data
for n in notes:
    with st.container(border=True):
        st.subheader(n["title"])
        st.write(n["body"])
        if st.button("Delete", key=f"del-{n['id']}"):
            supabase.table("notes").delete().eq("id", n["id"]).execute()
            st.rerun()

Data persists across sessions, devices, and deploys. No server to manage.

Step 5: Auth with Supabase

# Sign up
supabase.auth.sign_up({"email": email, "password": password})

# Sign in
res = supabase.auth.sign_in_with_password({"email": email, "password": password})
session = res.session

# Get current user
user = supabase.auth.get_user()

Store the session in st.session_state and gate pages (see Streamlit auth post).

Step 6: Storage (file uploads)

# Upload
with open("avatar.png", "rb") as f:
    supabase.storage.from_("avatars").upload("user1.png", f)

# Get public URL
url = supabase.storage.from_("avatars").get_public_url("user1.png")
st.image(url)

Great for profile pictures, PDF uploads, and generated reports.

Step 7: Real-time subscriptions

def handle_change(payload):
    st.toast(f"New note: {payload['new']['title']}")

supabase.table("notes").on("INSERT", handle_change).subscribe()

The callback fires when any client inserts a row — perfect for live dashboards and collaborative apps.

Supabase vs alternatives

Supabase Firebase PlanetScale SQLite (local)
DB Postgres NoSQL MySQL SQLite
Free tier 500MB 1GB 5GB Unlimited (local)
Auth Built-in Built-in No No
Real-time Yes Yes No No
Storage Yes Yes No Local only
Python SDK Excellent OK MySQL client Built-in
Best for Data apps, SaaS Mobile apps High-scale web Prototypes

Common mistakes

  • Using the service role key client-side — the anon key is for browsers; service role bypasses RLS. Never expose service role in Streamlit.
  • No RLS policies — without RLS, anyone with the anon key can read/write everything. Always enable RLS.
  • Storing secrets in code — use st.secrets or env vars.
  • Not handling auth errors — wrap calls in try/except; sessions expire.
  • Ignoring connection pooling — Supabase has connection limits on free tier; reuse the client.

Key Concepts

  • Supabase = managed Postgres + auth + storage + realtime
  • RLS = Row-Level Security (per-user data access)
  • anon key = safe for browsers (respects RLS)
  • service role key = server-only (bypasses RLS)
  • st.secrets = Streamlit’s secret management

What to Try Next

  • Add auth with Supabase Auth.
  • Build a data dashboard backed by Supabase.
  • Store uploaded PDFs in Supabase Storage for your RAG app.
  • Combine with FastAPI for a typed backend.

FAQ

Supabase free tier limits?

500MB database, 1GB storage, 2GB bandwidth, 50k monthly active users. Plenty for personal projects and small SaaS.

Supabase vs Firebase for Python?

Supabase has better Python support (official supabase-py client) and uses Postgres (SQL) instead of NoSQL. Firebase’s Python SDK is more limited. For data apps, Supabase wins.

Can I use Supabase with Streamlit Cloud?

Yes — store secrets in Streamlit Cloud’s secrets management (Settings → Secrets). The app reads them via st.secrets. Works great.