Streamlit sessionBrowser storage
This repo is to help streamlt users manage data in a browser's sessionBrowser storage.
Built on the use-session-storage-state that allows for real time updates especially important when sessionBrowser storage item is deleted.
for more details:
https://www.npmjs.com/package/use-session-storage-state
pip install streamlit-browser-session-storage
from streamlit_session_browser_storage import SessionStorage
sessionBrowserS = SessionStorage()
store items to sessionBrowser storage
itemKey = "camera"
itemValue = "Tarah"
sessionBrowserS.setItem(itemKey, itemValue)
get item from sessionBrowser storage
itemKey = "Taylor Swift"
sessionBrowser_storage_item = sessionBrowserS.getItem(itemKey)
get all items saved on sessionBrowser storage
saved_individual = sessionBrowserS.getAll()
st.write(saved_individual)
delete all
sessionBrowserS.deleteAll()
when getting sessionBrowser storage items with streamlit widgets
st.subheader("Method 1")
def sessionBrowserStorageManager():
return SessionStorage()
sessionBrowserS = sessionBrowserStorageManager()
if "get_val" not in st.session_state:
st.session_state["get_val"] = None
with st.form("get_data"):
st.text_input("key", key="get_sessionBrowser_storage_v")
st.form_submit_button("Submit")
if st.session_state["get_sessionBrowser_storage_v"] != "":
val_ = sessionBrowserS.getItem(st.session_state["get_sessionBrowser_storage_v"], key="test_get_item")
st.session_state["get_val"] = val_
st.write(st.session_state["get_val"])
### When using callbacks for get item, can use the below example. But it wont reveal data unless app has rendered twice. But callback can be work without a hitch generally (based on my tests).
st.subheader("Method 2 - using callback. Does not load instantly especially for get storage")
def sessionBrowserStorageManager():
return SessionStorage()
sessionBrowserS = sessionBrowserStorageManager()
if "get_val_2" not in st.session_state:
st.session_state["get_val_2"] = None
if "st_col_test" not in st.session_state:
st.session_state["st_col_test"] = None
def change_state_2():
with st.session_state["st_col_test"][0]: # call method from below form
sessionBrowserS.getItem(st.session_state["get_sessionBrowser_storage_v_2"], key="test_get_item_2") # initialise/run method and value will be stored in `session_state`
with st.form("get_data_2"):
st.text_input("key", key="get_sessionBrowser_storage_v_2")
st.form_submit_button("Submit", on_click=change_state_2)
st.session_state["st_col_test"] = st.columns(1) #to make sure rendering happens below form (or other streamlit element. Else the re-rendering of component upon re-running of up will be run at the top of the streamlit component (form here) which creates nasty ui experience.)
if "test_get_item_2" in st.session_state and st.session_state["test_get_item_2"] != None:
st.session_state["get_val_2"] = st.session_state["test_get_item_2"] # if sessionBrowser storage method is initialised, get the stored value and use it throughout the app.
st.write(st.session_state["get_val_2"])
Metadata
Release files for streamlit-browser-session-storage 0.0.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| streamlit_browser_session_storage-0.0.12.tar.gz | 536.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| streamlit_browser_session_storage-0.0.12-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.1 MB
Release files / streamlit_browser_session_storage-0.0.12.tar.gz
| Download URL | streamlit_browser_session_storage-0.0.12.tar.gz |
|---|---|
| Size | 536.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
20a2cd38698fa1900eb4d7086576319a8dda6b577f199142d954cdb56e2331fc
|
|
BLAKE2b-256 checksum How to use checksums |
d532c2198eb437154469366ffbe908810558ea91be96c2653d29ae6a8ea3dfd9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.19
|
Release files / streamlit_browser_session_storage-0.0.12-py3-none-any.whl
| Download URL | streamlit_browser_session_storage-0.0.12-py3-none-any.whl |
|---|---|
| Size | 543.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c0ed256b505592113978e99e53e4ed2d158d9e64013a758f6b36153b7309c358
|
|
BLAKE2b-256 checksum How to use checksums |
6dd7c76a401fb0ffcb9414203e7ead5eff6bf6d7cea1b38a1cb09bb448275e8e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.19
|
Security for streamlit-browser-session-storage 0.0.12
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.