Tech With Galvan
Back to Articles
DevelopmentSep 6, 2026 • 5 min read

Build an Admin Panel with Streamlit (CRUD, Auth, and Tables)

Build a full admin panel in Streamlit — CRUD operations, data tables, auth, search, and pagination. A reusable pattern for internal tools.

Galvan
Galvan

Founder & Creator

Introduction

Every app eventually needs an admin panel: view records, edit them, delete spam, manage users. Building one in React takes days. In Streamlit, it takes an afternoon — and you get a working, deployed tool.

This post is a reusable pattern: CRUD table + auth + search + pagination, backed by any database.

The pattern

┌─────────────────────────────────────────────┐
│  Sidebar: navigation + filters              │
├─────────────────────────────────────────────┤
│  Main: search bar + data table (st.dataframe)│
│        + edit form (expander)                │
│        + delete confirmation                 │
└─────────────────────────────────────────────┘

Setup

pip install streamlit pandas

We’ll use an in-memory list for the demo; swap for Supabase or SQLite in production.

Step 1: Auth gate

import streamlit as st

if not st.session_state.get("admin"):
    st.title("🔐 Admin Login")
    with st.form("login"):
        u = st.text_input("Username")
        p = st.text_input("Password", type="password")
        if st.form_submit_button("Login") and u == "admin" and p == "secret":
            st.session_state.admin = True
            st.rerun()
    st.stop()

See the auth post for production-grade auth.

Step 2: Mock data layer

# Replace with real DB calls
import pandas as pd
from datetime import datetime

if "records" not in st.session_state:
    st.session_state.records = [
        {"id": 1, "name": "Alice", "email": "[email protected]", "role": "admin", "active": True},
        {"id": 2, "name": "Bob", "email": "[email protected]", "role": "user", "active": True},
        {"id": 3, "name": "Carol", "email": "[email protected]", "role": "user", "active": False},
    ]

def get_records(search=""):
    df = pd.DataFrame(st.session_state.records)
    if search:
        mask = df["name"].str.contains(search, case=False) | df["email"].str.contains(search, case=False)
        df = df[mask]
    return df

Step 3: Search + table

st.title("🛠️ Admin Panel")
st.caption("Manage users")

search = st.text_input("🔍 Search by name or email")
df = get_records(search)

# Editable table
edited = st.data_editor(
    df,
    column_config={
        "id": st.column_config.NumberColumn("ID", disabled=True),
        "name": st.column_config.TextColumn("Name", required=True),
        "email": st.column_config.TextColumn("Email", required=True),
        "role": st.column_config.SelectboxColumn("Role", options=["admin", "user", "moderator"]),
        "active": st.column_config.CheckboxColumn("Active"),
    },
    hide_index=True,
    use_container_width=True,
    num_rows="dynamic",   # allow add/delete rows
)

if st.button("💾 Save changes"):
    st.session_state.records = edited.to_dict("records")
    st.success("Saved!")
    st.rerun()

st.data_editor is the killer feature — inline editing, dropdowns, checkboxes, and row add/delete, all in one component.

Step 4: Add new record form

with st.expander("➕ Add new user"):
    with st.form("add_user", clear_on_submit=True):
        name = st.text_input("Name")
        email = st.text_input("Email")
        role = st.selectbox("Role", ["user", "admin", "moderator"])
        if st.form_submit_button("Add") and name and email:
            new_id = max(r["id"] for r in st.session_state.records) + 1
            st.session_state.records.append({
                "id": new_id, "name": name, "email": email,
                "role": role, "active": True,
            })
            st.success(f"Added {name}")
            st.rerun()

Step 5: Bulk actions

st.subheader("Bulk actions")
selected = st.multiselect("Select users", options=[r["name"] for r in st.session_state.records])

col1, col2 = st.columns(2)
if col1.button("Deactivate selected") and selected:
    for r in st.session_state.records:
        if r["name"] in selected:
            r["active"] = False
    st.rerun()

if col2.button("Delete selected") and selected:
    st.session_state.records = [r for r in st.session_state.records if r["name"] not in selected]
    st.rerun()

Step 6: Pagination for large datasets

PAGE_SIZE = 20

if len(df) > PAGE_SIZE:
    page = st.number_input("Page", min_value=1, max_value=(len(df) // PAGE_SIZE) + 1, value=1)
    start = (page - 1) * PAGE_SIZE
    df_page = df.iloc[start:start + PAGE_SIZE]
    st.dataframe(df_page, use_container_width=True)
    st.caption(f"Showing {start+1}-{min(start+PAGE_SIZE, len(df))} of {len(df)}")
else:
    st.dataframe(df, use_container_width=True)

Step 7: Export

csv = df.to_csv(index=False).encode("utf-8")
st.download_button("📥 Export CSV", data=csv, file_name="users.csv", mime="text/csv")

Step 8: Audit log (bonus)

Track who changed what:

if "audit" not in st.session_state:
    st.session_state.audit = []

def log_action(action, target):
    st.session_state.audit.append({
        "time": datetime.now().isoformat(),
        "user": st.session_state.get("username", "unknown"),
        "action": action,
        "target": target,
    })

Show the audit log in a separate page or expander.

Common mistakes

  • No auth — admin panels without auth are a security disaster. Always gate.
  • Editing in data_editor without saving — changes are in-memory until you persist. Add a “Save” button.
  • No confirmation on delete — use st.dialog or a checkbox confirmation.
  • Loading all rows — paginate for >1000 rows.
  • No input validation — validate emails, required fields before saving.

Key Concepts

  • st.data_editor = inline-editable table
  • st.form = batched input (no rerun per keystroke)
  • st.session_state = in-memory data (swap for DB in prod)
  • Pagination = slice large datasets
  • Audit log = track changes for accountability

What to Try Next

FAQ

Streamlit admin panel vs Django admin?

Django admin is battle-tested, auto-generated from models, and handles permissions deeply. Streamlit admin is faster to build and customize, great for small teams and internal tools. Pick Django for large apps; Streamlit for quick internal tools.

Can I use this with a real database?

Yes — replace st.session_state.records with Supabase/Postgres/SQLite calls. The UI code stays the same; only the data layer changes.

Is Streamlit admin panel secure enough?

With proper auth (real backend, not hardcoded), HTTPS, and role-based access — yes for internal tools. For customer-facing admin, consider a proper framework (Django, Retool, or a custom React app).