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.9.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ce3be5bbbc5fe9a5e9688b5b9c851665231ab4c39a54b4e70177cc60027cebc |
|
MD5 | 683648cdd19de5b86c4d56e6e4b447fe |
|
BLAKE2b-256 | 108b7d01a53dfa5d4ec56551451753b5ee0a72099ba3bec2fd87b83dbb83fe5b |
Close
Hashes for streamlit_server_state-0.9.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89e66ad1e2855a1e3a6528197a5d6a3ed0dd519ed7955624a58a5ee3bf2b560e |
|
MD5 | 852165b5d05459034293d612f09a766d |
|
BLAKE2b-256 | dfc0d665eb9d6a35faaafd1a7385ed13880749abc02d3f8d34f319c7b504c9fd |