No project description provided
Project description
streamlit-server-state
A "server-wide" state shared across the sessions.
import streamlit as st
from streamlit_server_state import server_state, server_state_lock
st.title("Global Counter Example")
with server_state_lock["count"]: # Lock the "count" state for thread-safety
if "count" not in server_state:
server_state.count = 0
increment = st.button("Increment")
if increment:
with server_state_lock.count:
server_state.count += 1
decrement = st.button("Decrement")
if decrement:
with server_state_lock.count:
server_state.count -= 1
st.write("Count = ", server_state.count)
As above, the API is similar to the built-in SessionState, except one major difference - a "lock" object. The lock object is introduced for thread-safety because the server-state is accessed from multiple sessions, i.e. threads.
Examples
app_global_count
: A sample app like the official counter example for SessionState which usesstreamlit-server-state
instead and the counter is shared among all the sessions on the server. This is a nice small example to see the usage and behavior ofstreamlit-server-state
. Try to open the app in multiple browser tabs and see the counter is shared among them.app_global_slider
: A slider widget (st.slider
) whose value is shared among all sessions.app_chat.py
: A simple chat app usingstreamlit-server-state
.app_chat_rooms.py
: A simple chat app with room separation.
Resources
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for streamlit-server-state-0.11.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46fc3e2a299f221e5f53bb7c65642c2f8815e188d53a556bf166351a51afdf1a |
|
MD5 | fdcb1af20c6de8ec0b37c78d218dc21d |
|
BLAKE2b-256 | a3568d9c618983660ddaa6424c70c31553ddae47a0d6ef8ff2cb9fd1bff6354d |
Close
Hashes for streamlit_server_state-0.11.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45656af3415af0827cab2bd56b33a999167924bed988ee16185fac8cf8954c69 |
|
MD5 | 12acb2c3f77d493cf538e778da83bd13 |
|
BLAKE2b-256 | cb7816961ac50211c0130c604b4e697a0368f5cb42557ce2e563bbf0166fada8 |