
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
streamlit-state-model
Advanced tools
A package that provides a StateModel for Streamlit applications, allowing easy management of session state through class attributes.
I love Streamlit, but working with st.session_state
can be tedious. Coming from an OOP background, I cringe at managing each key in st.session_state
individually, checking if it exists, and losing intellisense for names and types.
So I made streamlit-state-model
which offers a base class StateModel
that you can subclass to push your class' attribute I/O directly into st.session_state
. This means you define what should exist in st.session_state
once in the form of a normal python class, and then access those values anywhere in your Streamlit app with the expected statefulness of st.session_state
.
st.session_state
so class attribute values are retained across page refreshes and switches (in multi-page apps).StateModel
can be used with existing or new class definitions.st.session_state
with normal class' default annotations and gain the ability to reset them all to defaults with a single function call.st.session_state
by inspecting your class' attribute values.st.session_state
.if
checks around current state of st.session_state
.docstrings
dictionary within your app.Install the package using pip:
pip install streamlit-state-model
Take your existing class 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 of your app, initialize your class 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 initialize in lazy (default) mode to access current 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 multipage app on Streamlit Community Cloud. Check out: state-model-demo-app.
We're also working on generating API docs for StateModel
since it already includes many helper functions such as:
dump()
: Dump all class attribute values to a JSON string (often paired with st.json
).StateModel
following Streamlit's recommended patterns. (See the Streamlit Documentation on Multipage Apps for details.)For details on contributing and the CI/CD process, please refer to the development documentation.
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.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.