using-streamlit-session-state

Manage persistent state across Streamlit reruns using st.session_state.

1|Updated Mar 22, 2026
One-click install
npx skills add https://github.com/michaelschecht/Edge-Radar --skill using-streamlit-session-state-michaelschecht
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: using-streamlit-session-state
Source: https://github.com/michaelschecht/Edge-Radar/tree/main/.claude/skills/developing-with-streamlit/skills/using-streamlit-session-state
Command: npx skills add https://github.com/michaelschecht/Edge-Radar --skill using-streamlit-session-state-michaelschecht

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Streamlit reruns scripts top-to-bottom on every interaction, leading to resetting of variables. This skill helps manage state across reruns.

Core Features & Use Cases

  • Persist Variables: Use st.session_state to persist data across reruns.
  • Widget Integration: Widgets with a key parameter automatically sync to session state.
  • Callback Management: Use callbacks to update state before script reruns.
  • Initialization Patterns: Organize state at the top of your app for clarity.
  • Multipage State: Share data across pages using session state variables.

Quick Start

Use the skill to increment a counter by adding 5 every time a button is clicked.

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

To persist variables across Streamlit reruns, use `st.session_state` to store data. This prevents variables from resetting when the script executes top-to-bottom after each user interaction.

Why does my Streamlit app reset data on every interaction?

Your Streamlit app resets data because the framework reruns scripts top-to-bottom on every interaction. Managing state with `st.session_state` solves this by maintaining persistent data across reruns.

How do I share data across multiple pages in a Streamlit app?

You can share data across multiple pages in a Streamlit app by storing variables in `st.session_state`. This allows multipage applications to access and update the same persistent data.

Do Streamlit widgets automatically sync with session state?

Streamlit widgets automatically sync with session state when you assign them a `key` parameter. This binds the widget's value directly to `st.session_state` for seamless state management.

What is the best way to initialize session state in a Streamlit app?

The best way to initialize session state in a Streamlit app is organizing state assignments at the top of your script. This initialization pattern ensures clarity and consistent data availability before workflows execute.

Can I use callbacks to update Streamlit session state?

You can use callbacks to update Streamlit session state before script reruns. This allows you to manage state changes proactively, ensuring data is updated prior to the script execution cycle.