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.2.6.tar.gz (6.9 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.2.6-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for streamlit_state_manager-0.2.6.tar.gz
Algorithm Hash digest
SHA256 c8f20857eab128c7b37cb75bdb45fb44bd272c452f044a7e2d4ebadd960a7e31
MD5 ba45ad6fe768169ed9d70f6bb638e1e2
BLAKE2b-256 18b61e1ec348c1cdea648fb878b43f7e2662b69ae2ddfe12ab08dcec0dc45b89

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for streamlit_state_manager-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 dcc97229e3fcaa6171e55b89162e6ac082bcd1ffee5e51748bf95be7c75a21eb
MD5 dd3fc87951c3ee61aae54e98f14721f3
BLAKE2b-256 1e5e866a6d698a928bbf76750f9c3fcb624adce2ec362808a33a0d31b57f0a07

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