using-streamlit-session-state

Manage state across Streamlit reruns with st.session_state.

224|23|Updated Jan 14, 2026
One-click install
npx skills add https://github.com/streamlit/agent-skills --skill using-streamlit-session-state-streamlit
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: using-streamlit-session-state
Source: https://github.com/streamlit/agent-skills/tree/main/developing-with-streamlit/skills/using-streamlit-session-state
Command: npx skills add https://github.com/streamlit/agent-skills --skill using-streamlit-session-state-streamlit

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Streamlit reruns scripts top-to-bottom on every interaction. Without session state, variables reset each time. Use st.session_state to persist values across reruns.

Core Features & Use Cases

  • Session state is a dictionary-like object supporting attribute and bracket notation.
  • Widget-state association via the key parameter automatically syncs widget values to session state.
  • Initialization patterns with setdefault provide a safe, predictable starting point for app state.
  • Per-user, per-tab state management enables stable experiences across interactions and pages.

Quick Start

Initialize state at the top of your app using the session-state API and interact with it throughout user interactions.

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 variable values across Streamlit reruns?▼

To persist variable values across Streamlit reruns, use st.session_state, a dictionary-like object that stores per-user data and prevents variables from resetting on each interaction.

Why do my Streamlit widgets reset their values on every interaction?▼

Streamlit widgets reset their values because the script reruns top-to-bottom on every interaction. You can sync widget values to session state by assigning a key parameter to the widget.

What is the best way to initialize state in a Streamlit multi-page app?▼

The best way to initialize state in a Streamlit multi-page app is using the setdefault method on st.session_state, which provides a safe and predictable starting point for per-user state without overwriting existing values.

Can I use session state to manage per-user and per-tab data in Streamlit?▼

Yes, you can use session state to manage per-user and per-tab data in Streamlit. It enables stable experiences across interactions and pages by isolating state for each user session.

How do callbacks work with st.session_state in Streamlit?▼

Callbacks in Streamlit work with st.session_state by synchronizing widget values through the key parameter, allowing you to read and modify state safely when a widget value changes during a rerun.