using-streamlit-session-state

Manage application state across Streamlit reruns using st.session_state.

Updated Feb 13, 2026
One-click install
npx skills add https://github.com/Aaron-Tawil/super-order-automation --skill using-streamlit-session-state-aaron-tawil
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: using-streamlit-session-state
Source: https://github.com/Aaron-Tawil/super-order-automation/tree/main/.codex/skills/developing-with-streamlit/skills/using-streamlit-session-state
Command: npx skills add https://github.com/Aaron-Tawil/super-order-automation --skill using-streamlit-session-state-aaron-tawil

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses the challenge of maintaining data and user interactions across multiple reruns in Streamlit applications, ensuring a seamless user experience.

Core Features & Use Cases

  • State Persistence: Reliably store and retrieve variables between user interactions.
  • Widget State Synchronization: Automatically link widget values to session state.
  • Callback Handling: Execute functions in response to user actions, updating state immediately.
  • Use Case: Build a multi-page Streamlit app where user selections on one page are remembered and used on subsequent pages, or create interactive dashboards where filters applied by the user persist as they navigate through different views.

Quick Start

Initialize a session state variable named 'counter' to zero and display its current value.

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 reruns?

To persist data across Streamlit reruns, use `st.session_state` to store and retrieve variables. This manages application state, ensuring user interactions and widget values remain intact throughout the execution cycle.

What is the best way to synchronize widget values with session state in Streamlit?

Synchronizing widget values with session state in Streamlit involves linking widgets directly to `st.session_state` keys. This automatically updates and persists user interactions without requiring manual value extraction during reruns.

How do I handle callbacks for user actions in Streamlit?

Handle callbacks for user actions in Streamlit by assigning functions to widget `on_change` parameters. These callbacks execute immediately, updating `st.session_state` before the main script reruns to reflect new state.

Why does my Streamlit app lose user selections when navigating multiple pages?

Your Streamlit app loses user selections because variables reset on each rerun. Initializing variables in `st.session_state` ensures data persistence, allowing selections on one page to be remembered on subsequent pages.

Do I need to understand Streamlit's execution model to use session state effectively?

Yes, understanding Streamlit's execution model is required for effective session management. Knowing how the script reruns top-to-bottom after interactions allows you to correctly initialize and update `st.session_state` variables.

What are the limitations of using session state for data persistence in Streamlit?

A limitation of using session state for data persistence in Streamlit is that data is scoped only to the current user session. It does not share state across different users or permanently store data outside the active browser session.