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.14.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a322e79015d8d5e3abc788aae8ec9d70ae5020758667928d10ad6d414968d0a2 |
|
MD5 | 69d586f3a677b2d311560d067b0a6a29 |
|
BLAKE2b-256 | c6c2be8a1faf047c35aae97ce86c11516508c695c34fc2ae0d28ca55e8858be1 |
Close
Hashes for streamlit_server_state-0.14.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96fc93c0e0fa19c21da685eb2298bb2bfec0f66eb48eb8c1466dad5d988a2376 |
|
MD5 | be978acb3c848245427bcc00bf833d73 |
|
BLAKE2b-256 | c59b957486b4b7d39ca568ffb3617d197ff38ca81d08b3d27c550b183407e7b9 |