No project description provided
Project description
streamlit-session-memo
A decorator for session-specific caching on Streamlit.
from streamlit_session_memo import st_session_memo
@st_session_memo
def load_big_model():
...
return model
model = load_big_model()
This is a simple wrapper around st.session_state
that caches the return value of the decorated function to the session state and returns the cached value if the function is called again with the same arguments.
We have been doing this manually with code like the following, but this decorator makes it simpler.
# Boilerplate code for session-specific caching.
cache_key = f"{arg_1}_{arg_2}_{arg_3}"
if cache_key in st.session_state:
model = st.session_state[cache_key]
else:
result = load_expensive_model(arg_1, arg_2, arg_3)
st.session_state[cache_key] = result
model = result
Note that, this decorator is a lightweight wrapper around st.session_state
that acts like the code snippet above, and does not provide any additional features such as mutation guards that st.cache_data
provides.
Project details
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_session_memo-0.3.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4aad0b348d7cad94c2f307fc62175d1d9f182f94699577147f010b6f43621f8d |
|
MD5 | af3059eae3380fbefdefdbc3db703da8 |
|
BLAKE2b-256 | 5fbdc653de6b2f2dbec80e35eb7f43d20a3c3af3438d75148cf00eb6898e7b63 |
Close
Hashes for streamlit_session_memo-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29f8b1602686de6f09dd998ea5a05e11fc12e6ac7de199d2677124f342417563 |
|
MD5 | d0196d01e4d8126ca91b64bdb9dc1b0b |
|
BLAKE2b-256 | 476a5551de70099c761026e42db5cd4d20d527134d7dba36fa12b95d2e270da6 |