Skip to main content

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

Arguments are hashed the way st.cache_data and st.cache_resource hash theirs, by delegating to Streamlit's own key builder: values such as dicts and DataFrames are keyed by content, passing an argument positionally or by keyword gives the same key, a parameter whose name starts with an underscore is left out of the key, and an argument of a type Streamlit cannot hash raises UnhashableParamError. That exception is Streamlit's own, so its message suggests @st.cache_resource; the underscore it advises works the same way here.

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.

Metadata

Release files for streamlit-session-memo 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for streamlit-session-memo 0.5.0
File Size Uploaded
streamlit_session_memo-0.5.0.tar.gz 77.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for streamlit-session-memo 0.5.0
File Interpreter ABI Platform
streamlit_session_memo-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 82.4 kB

Release files / streamlit_session_memo-0.5.0.tar.gz

Download URL streamlit_session_memo-0.5.0.tar.gz
Size 77.9 kB
Tags Source
SHA-256 checksum
How to use checksums
18b1aa14a6086a1bebb2875aabba02b7e681cd48f2fe469129fd0382231981be
BLAKE2b-256 checksum
How to use checksums
1641ae8b17953b30951a6cf6670c9efc947118f66354194fbb82f5453935ae1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 24, 2026.

Transparency log

Release files / streamlit_session_memo-0.5.0-py3-none-any.whl

Download URL streamlit_session_memo-0.5.0-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c9acec0a45f3a0bf597fafebb7d1e70b091f98be874faa82cef35f02542bc7e
BLAKE2b-256 checksum
How to use checksums
2ab13dc875256244f1226a746429e21c6875783846a31bc5531765d411818077
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 24, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page