You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

streamlit-state-manager

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

streamlit-state-manager

A wrapper around Streamlit's session state for easier state management

0.2.6
pipPyPI
Maintainers
1

Streamlit State Manager

The Streamlit State Manager StateManager is essentially a wrapper around Streamlit's native st.session_state dictionary, that simplifies how you interact with it.

Features

  • Cleaner Code: Reduces boilerplate for initialization and access
  • Error Prevention: Reduces common pitfalls like missing initialization

Installation

pip install streamlit-state-manager

Examples

1. Simplified Access Patterns

Without StateManager:

# Check if exists, initialize, then get
if "counter" not in st.session_state:
    st.session_state["counter"] = 0
count = st.session_state["counter"]

# Updating value
st.session_state["counter"] += 1

With StateManager:

# Get with auto-initialization
count = StateManager.get("counter", 0)

# Updating value
StateManager.set("counter", count + 1)

2. Prevention of Common Errors

Without StateManager:

# Potential KeyError if key doesn't exist
value = st.session_state["maybe_missing_key"]

# Forgetting to check existence before using
st.session_state["counter"] += 1  # Error if counter doesn't exist

With StateManager:

# Safe access with optional default
value = StateManager.get("maybe_missing_key", default_value=None)

License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts