Streamlit st.session_state limits: server-side memory and per-tab session scope
0 reputation · 07 Feb 2020, 07:02 UTC
Streamlit's st.session_state is documented to persist values across script reruns within a single user session, behaving like a Python dictionary that can hold complex objects such as DataFrames. State is scoped to one browser tab and stored on the server side, so every object placed there occupies memory in the server process for the lifetime of that session.
A design question arises when an app needs to keep a moderately sized DataFrame plus derived values available across reruns. The documented behavior covers persistence and isolation, but it does not state a size ceiling, and large session objects raise the server's memory footprint while multiple tabs multiply that usage. State is also not shared between users, which pushes any global data toward external storage.
Specific questions:
- Is there a documented or practical upper bound on object size in
st.session_statebefore server memory becomes a risk? - How does per-tab session isolation scale aggregate memory use when one user opens several tabs?
- What criteria should separate session-scoped data from data better held in
st.cache_dataor an external database?