Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
streamlit-state-model
Advanced tools
A package that provides a StateModel for Streamlit applications, allowing easy management of session state through class attributes.
Tired of writing repetitive if key not in st.session_state
checks in your Streamlit apps?
Introducing StateModel
- a streamlined solution that lets you manage session_state
effortlessly through standard Python class definitions. With StateModel
, you can store and retrieve class attributes directly in session_state
without any extra hassle, making your code cleaner and more maintainable.
session_state
.if
statements for session_state
interaction.session_state
.StateModel
.docstrings
dictionary within your app.Install the package using pip:
pip install streamlit-state-model
Just take your existing class definition and subclass StateModel
.
import streamlit_state_model as ssm
class Session(ssm.StateModel):
favorite_color: str = "#252D3D"
"The user's favorite color as a hex string."
favorite_number: int = 0
"The user's favorite number."
At the entry point to your app, init an instance of your class definition in "build" mode.
#streamlit_app.py
session = Session(mode="build")
st.write(session.favorite_number) #outputs default value of 0
session.favorite_number = 1 #set to a new value
""
Anywhere else in your app you can init an instance of your StateModel
using lazy (default) mode. StateModel
is a singleton like storage of your class instance, so when you init an instance of your class after building it, it does nothing except provide the class interface to your python code for accessing your class' attribute values.
#pages/page_1.py
session = Session() #init in lazy mode
st.write(session.favorite_number) #outputs 1 as set in streamlit_app.py
""
Explore our demo Streamlit app in the /demo_app
directory for an example of integrating StateModel
into a multi-page app (coming soon to the Streamlit Community).
We're also working on generating API docs for StateModel
because it already inclues many helper functions (with more to come) such as:
dump()
: View all attribute values.StateModel
following Streamlit's recommended patterns (For more details, refer to the Streamlit Documentation on Working with Widgets in Multipage Apps).If you have an idea for a new feature or have found a bug, please open an issue or submit a pull request. I don't have a formal code of conduct or contribution guidelines yet, but I appreciate respectful and constructive contributions.
The project is built with Flit and a Conda development environment (dev_environment.yml) is provided in the project root.
Tests are built using pytest and Streamlit's app testing framework ran against the demo app.
FAQs
A package that provides a StateModel for Streamlit applications, allowing easy management of session state through class attributes.
We found that streamlit-state-model demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.