Skip to main content

Streamlit local storage

This repo is to help streamlt users manage data in a browser's local storage. Built on the use-local-storage-state that allows for real time updates especially important when local storage item is deleted.

for more details: https://www.npmjs.com/package/use-local-storage-state

pip install streamlit-local-storage

store items to local storage

from streamlit_local_storage import LocalStorage
localS = LocalStorage()

itemKey = "camera"
itemValue = "Tarah"
localS.setItem(itemKey, itemValue)

get item from local storage

itemKey = "Taylor Swift"
local_storage_item = localS.getItem(itemKey)

get all items saved on local storage

saved_individual = localS.getAll()
st.write(saved_individual)

delete all

localS.deleteAll()

when getting local storage items with streamlit widgets

st.subheader("Method 1")

def LocalStorageManager():
    return LocalStorage()
localS = LocalStorageManager()

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_local_storage_v")
    st.form_submit_button("Submit") 

if st.session_state["get_local_storage_v"] != "":
    val_ = localS.getItem(st.session_state["get_local_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 LocalStorageManager():
    return LocalStorage()
localS = LocalStorageManager()

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
        localS.getItem(st.session_state["get_local_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_local_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 local storage method is initialised, get the stored value and use it throughout the app.
st.write(st.session_state["get_val_2"])


Remember to refresh browser if it does not pop up instantly in local storage.

Release files for streamlit-local-storage 0.0.25

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-local-storage 0.0.25
File Size Uploaded
streamlit_local_storage-0.0.25.tar.gz 538.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for streamlit-local-storage 0.0.25
File Interpreter ABI Platform
streamlit_local_storage-0.0.25-py3-none-any.whl Python 3 none any Details

Total release size: 1.1 MB

Release files / streamlit_local_storage-0.0.25.tar.gz

Download URL streamlit_local_storage-0.0.25.tar.gz
Size 538.4 kB
Tags Source
SHA-256 checksum
How to use checksums
9b7c3e8ae7c14a68b47c980b167306181292213736dfa71850c8d3204dc2a9cd
BLAKE2b-256 checksum
How to use checksums
d1ad5e92a9355c2f32c162f0e2a2262b90697385edf0fe64bc66a27eb652ac95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release files / streamlit_local_storage-0.0.25-py3-none-any.whl

Download URL streamlit_local_storage-0.0.25-py3-none-any.whl
Size 543.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0ef85618ed8c44f347b7acffb2d104da5b6915e6a4e24612f12a4d2cc355b951
BLAKE2b-256 checksum
How to use checksums
7ba6502b00b6db10c3d467ec57d822d6647a35f0328ef03668aa5b6dd160f966
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release history Release notifications | RSS feed

This release

0.0.25 This release

2 release files

0.0.24

2 release files

0.0.23

2 release files

0.0.21

2 release files

0.0.20

2 release files

0.0.19

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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