Skip to main content

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

Project description

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

  1. Cleaner Code: Reduces boilerplate for initialization and access
  2. 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_state_manager-0.1.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamlit_state_manager-0.1.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_state_manager-0.1.0.tar.gz.

File metadata

  • Download URL: streamlit_state_manager-0.1.0.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.9

File hashes

Hashes for streamlit_state_manager-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1839d163f17e2d58f4e96ec679c5dd1820d36099f529967dc091f72287ef41f6
MD5 ac78e2d99aa0814bd1144c23ddffb133
BLAKE2b-256 94e603a20c25e167c13bf74d0c736fff20568de3695987203bcb1fca637c41c9

See more details on using hashes here.

File details

Details for the file streamlit_state_manager-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_state_manager-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b81e7f33fb5b34cbdd8db752df00f30ba494d0c59448394d0025b1a5ddbf83b4
MD5 3076457ab5eaf731426d14421b2697ad
BLAKE2b-256 d0a1e3a95b9bc381231b8fa05ef7d5cbebbbe9fe2c8107861b059dfaf726dae9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page