using-streamlit-session-state

Manage persistent widget state across Streamlit reruns with st.session_state.

Updated Feb 19, 2026
One-click install
npx skills add https://github.com/guihousun/NTL-GPT-Clone --skill using-streamlit-session-state-guihousun
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: using-streamlit-session-state
Source: https://github.com/guihousun/NTL-GPT-Clone/tree/main/skills/developing-with-streamlit/skills/using-streamlit-session-state
Command: npx skills add https://github.com/guihousun/NTL-GPT-Clone --skill using-streamlit-session-state-guihousun

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Streamlit apps re-execute top-to-bottom on every interaction, causing loss of local state unless you use st.session_state. This guide shows how to persist data across reruns, manage widget state, implement callbacks, and avoid common gotchas.

Core Features & Use Cases

  • Persist widget values across reruns using st.session_state keys.
  • Bind widget state to callbacks and enable multi-page state sharing.
  • Debug and reason about state flow in Streamlit apps.

Quick Start

Initialize and access session state at app startup with st.session_state.setdefault("user", None) and reference it in widgets.

Frequently Asked Questions about using-streamlit-session-state

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

FAQPage Schema
How do I persist widget state across Streamlit reruns?

You can persist Streamlit widget state by initializing keys with st.session_state.setdefault and binding widgets to them. This ensures values survive the top-to-bottom script re-execution triggered by user interactions.

Why does my Streamlit dashboard lose local state on interaction?

Streamlit apps lose local state because they re-execute the entire script top-to-bottom on every interaction. Using st.session_state allows you to manage persistent data and avoid losing widget values during these reruns.

What is the best way to manage multi-page state sharing in Streamlit?

The best way to manage multi-page state sharing in Streamlit is by storing shared values in st.session_state. Initialize keys at startup and use callback-driven updates to ensure consistent state across different pages.

How do I bind Streamlit widget updates to callbacks?

To bind Streamlit widget updates to callbacks, assign a key to your widget and reference that key in st.session_state. This callback-driven approach ensures consistent state updates when widget values change.

Can I debug state flow in a Streamlit multi-page app?

Yes, you can debug state flow in a Streamlit multi-page app by reasoning about your st.session_state initialization and key-based widget binding. This helps identify state management gotchas and ensures consistent values.