Skip to main content

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

streamlit_session_memo-0.3.2.tar.gz (95.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamlit_session_memo-0.3.2-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_session_memo-0.3.2.tar.gz.

File metadata

  • Download URL: streamlit_session_memo-0.3.2.tar.gz
  • Upload date:
  • Size: 95.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for streamlit_session_memo-0.3.2.tar.gz
Algorithm Hash digest
SHA256 a7b020432790755092060cdbb77d89f4ab5c38c4ca537c6c19b07ae265ee371a
MD5 41ae378c060e2fd2c4efde93f5a2d33a
BLAKE2b-256 c048f3f98d98ed709d8b25408de3e799d6c6e2d271fc31aae4de479f7cbe7006

See more details on using hashes here.

Provenance

The following attestation bundles were made for streamlit_session_memo-0.3.2.tar.gz:

Publisher: main.yml on whitphx/streamlit-session-memo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file streamlit_session_memo-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_session_memo-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a9f21d7a8c7724771341bc72693df3506e002a304a5e05a3d18b7eef04a7bece
MD5 8053044891607cb5967cf03292aa56dd
BLAKE2b-256 eaae1bad7e9cd7d6f2db97bca3b7183ea8ac25544bd375c18ceb58448278f258

See more details on using hashes here.

Provenance

The following attestation bundles were made for streamlit_session_memo-0.3.2-py3-none-any.whl:

Publisher: main.yml on whitphx/streamlit-session-memo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page