using-streamlit-session-state

Manage persistent state across Streamlit reruns with st.session_state.

1|1|Updated Nov 9, 2025
One-click install
npx skills add https://github.com/Paldom/databricks-apps-streamlit-vibe-coding-starter --skill using-streamlit-session-state-paldom
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: using-streamlit-session-state
Source: https://github.com/Paldom/databricks-apps-streamlit-vibe-coding-starter/tree/main/.agents/skills/developing-with-streamlit/skills/using-streamlit-session-state
Command: npx skills add https://github.com/Paldom/databricks-apps-streamlit-vibe-coding-starter --skill using-streamlit-session-state-paldom

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses the challenge of maintaining data and widget states across multiple user interactions within a Streamlit application, preventing data loss and ensuring a smooth user experience.

Core Features & Use Cases

  • State Persistence: Stores variables and widget states across script reruns.
  • Widget Synchronization: Automatically links widget values to session state using the key parameter.
  • Callback Handling: Enables state updates before script reruns via on_change and on_click.
  • Use Case: In an interactive data visualization app, use session state to remember the user's selected filters and chart type, so they don't have to re-select them every time they interact with the plot.

Quick Start

Initialize a session state variable named 'counter' to zero using st.session_state.setdefault.

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 data across Streamlit script reruns?

To persist data across Streamlit reruns, use st.session_state to store variables and widget states, preventing data loss when the script executes again after user interactions.

How do I synchronize Streamlit widget values with session state?

Synchronize Streamlit widget values with session state by assigning a unique key parameter to the widget, which automatically links the widget's current value to the corresponding session state entry.

Why does my Streamlit callback execute state changes inconsistently?

Streamlit callback state changes require using on_change or on_click parameters to execute updates before the script reruns, avoiding the common pitfall of modifying state after widget creation.

Can I share session state across multiple pages in a Streamlit app?

You can share session state across multiple pages in a Streamlit app by utilizing established patterns for multipage state sharing, ensuring data remains consistent throughout different navigation routes.

What are the limitations of using module-level mutable state in Streamlit?

Module-level mutable state in Streamlit causes unexpected behavior because it persists across user sessions, whereas st.session_state isolates variables per user session to prevent data cross-contamination.