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.6.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7be54e655b44f1534a29290b46fead5d6fc3bb977b9b3fad59b76e987360c8ab |
|
MD5 | 4ba90cd6ef6ae43b8d9589cd92c5975f |
|
BLAKE2b-256 | aefe4f182926308d54d58c0b6dfe750d17bb57db7f435f9c31a2990d2877247f |
Close
Hashes for streamlit_server_state-0.6.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1db2a810afc0f0cdeee6ed97513066f0c30b91c7a94bb06bb1a8105dd6f279a |
|
MD5 | 546e15860783c39c6371673e2bb4b80c |
|
BLAKE2b-256 | 4f7b4e0811b84924d3730994dc43a2e8905858e5007c3821937099b1b8e9fbf8 |