No project description provided
Project description
streamlit-server-state
A "server-wide" state shared among the sessions.
import streamlit as st
from streamlit_server_state import server_state, server_state_lock
st.title("Global Counter Example")
if server_state_lock["count"]: # Obtain a lock for 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_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.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d628d8858374288fd68cfbd5b437acf49e302809f32d113bdbf3f9e069936748 |
|
MD5 | e421873bb2f0e40d7edd7629c7a48df0 |
|
BLAKE2b-256 | ea22971bf612e0159f6551d0a3524523a87d3250ed9a04c41d3c4a0652f3e477 |
Close
Hashes for streamlit_server_state-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8bc48d90256a44617620f99140472aec352d6db3a950c094b9b5c65f3ef1841 |
|
MD5 | 2c05bb681cc63fd4ecad6edfcd170fe2 |
|
BLAKE2b-256 | c8b7e8671082626f3f60b508747b7bc5a232553ad617b8e8147ce9fb42de6fd4 |