Name | streamlit-session-memo JSON |
Version |
0.3.1
JSON |
| download |
home_page | |
Summary | |
upload_time | 2023-04-27 12:34:05 |
maintainer | |
docs_url | None |
author | Yuichiro Tachibana (Tsuchiya) |
requires_python | >=3.8, !=2.7.*, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, !=3.6.*, !=3.7.* |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# streamlit-session-memo
A decorator for session-specific caching on Streamlit.
```python
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.
```python
# 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.
Raw data
{
"_id": null,
"home_page": "",
"name": "streamlit-session-memo",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8, !=2.7.*, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, !=3.6.*, !=3.7.*",
"maintainer_email": "",
"keywords": "",
"author": "Yuichiro Tachibana (Tsuchiya)",
"author_email": "t.yic.yt@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/5f/bd/c653de6b2f2dbec80e35eb7f43d20a3c3af3438d75148cf00eb6898e7b63/streamlit_session_memo-0.3.1.tar.gz",
"platform": null,
"description": "# streamlit-session-memo\n\nA decorator for session-specific caching on Streamlit.\n\n```python\nfrom streamlit_session_memo import st_session_memo\n\n\n@st_session_memo\ndef load_big_model():\n ...\n return model\n\n\nmodel = load_big_model()\n```\n\nThis 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.\nWe have been doing this manually with code like the following, but this decorator makes it simpler.\n```python\n# Boilerplate code for session-specific caching.\ncache_key = f\"{arg_1}_{arg_2}_{arg_3}\"\nif cache_key in st.session_state:\n model = st.session_state[cache_key]\nelse:\n result = load_expensive_model(arg_1, arg_2, arg_3)\n st.session_state[cache_key] = result\n model = result\n```\n\nNote 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.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "",
"version": "0.3.1",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "476a5551de70099c761026e42db5cd4d20d527134d7dba36fa12b95d2e270da6",
"md5": "d0196d01e4d8126ca91b64bdb9dc1b0b",
"sha256": "29f8b1602686de6f09dd998ea5a05e11fc12e6ac7de199d2677124f342417563"
},
"downloads": -1,
"filename": "streamlit_session_memo-0.3.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d0196d01e4d8126ca91b64bdb9dc1b0b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8, !=2.7.*, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, !=3.6.*, !=3.7.*",
"size": 3260,
"upload_time": "2023-04-27T12:34:03",
"upload_time_iso_8601": "2023-04-27T12:34:03.436665Z",
"url": "https://files.pythonhosted.org/packages/47/6a/5551de70099c761026e42db5cd4d20d527134d7dba36fa12b95d2e270da6/streamlit_session_memo-0.3.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5fbdc653de6b2f2dbec80e35eb7f43d20a3c3af3438d75148cf00eb6898e7b63",
"md5": "af3059eae3380fbefdefdbc3db703da8",
"sha256": "4aad0b348d7cad94c2f307fc62175d1d9f182f94699577147f010b6f43621f8d"
},
"downloads": -1,
"filename": "streamlit_session_memo-0.3.1.tar.gz",
"has_sig": false,
"md5_digest": "af3059eae3380fbefdefdbc3db703da8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8, !=2.7.*, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, !=3.6.*, !=3.7.*",
"size": 2489,
"upload_time": "2023-04-27T12:34:05",
"upload_time_iso_8601": "2023-04-27T12:34:05.425937Z",
"url": "https://files.pythonhosted.org/packages/5f/bd/c653de6b2f2dbec80e35eb7f43d20a3c3af3438d75148cf00eb6898e7b63/streamlit_session_memo-0.3.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-27 12:34:05",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "streamlit-session-memo"
}