legout/pi-config/using-streamlit-session-state
Claude Code and agent skill by legout/pi-config
- community
Checking that the SKILL.md file is still in the repository.
Using st.session_state to manage state across Streamlit reruns. Use when persisting data, handling widget state, implementing callbacks, or debugging state issues. Covers initialization patterns, widget-state association, and common gotchas.
Install
npx vskill@latest install legout/pi-config/using-streamlit-session-stateSKILL.md
The same SKILL.md was published earlier as legout/pi-config/using-streamlit-session-state.
Using Streamlit session state
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.
Basic usage
Session state is a dictionary-like object supporting attribute and bracket notation:
Accessing uninitialized keys raises `KeyError`. Use st.session_state.get("key", default) for safe access.
Widget-state association
Every widget with a key parameter automatically syncs to session state:
Callbacks
Callbacks execute before the script reruns, allowing immediate state changes. Use on_change or on_click with optional args and kwargs:
Access a widget's value in its own callback via st.session_state.key, not the return variable.
Initialization patterns
Initialize all state at the top of your app for clarity:
Multipage state
Widgets are NOT stateful across pages. Their values reset when navigating between pages.
Sharing state
Use session state variables (not widget keys) to share data:
Shared widgets pattern
Put common widgets in the entrypoint file (before nav.run()):
Common mistakes
Module-level mutable state
Modifying state after widget creation
Cannot assign to a widget's state after the widget has rendered:
Mixing value parameter and session state
Don't set both—it causes warnings:
Session characteristics
- Per-user, per-tab: Each browser tab has its own session
- Temporary: Lost when tab closes or server restarts
- Not suitable for persistence: Use databases for permanent storage
References
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckinginstalled-skills/developing-with-streamlit/skills/using-streamlit-session-state/SKILL.md
Popularity
- Repository stars
- 3
- 7-day trend score
- 0
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/legout/pi-config/using-streamlit-session-state)