Skip to main content

A simple synchronous way of accessing localStorage from your Streamlit app.

Project description

streamlit-ws-localstorage

Finally a simple synchronous way of accessing localStorage from your Streamlit app.

Why

I tried using extra-streamlit-components but found it too complex, because of the way Streamlit components works. Since the communication between the browser and streamlit app is async, your app is run multiple times, and nested if else blocks may not work properly. A simple call to get all cookies causes the app to be run 4 times in total. And the first call to get all cookies returns an empty dictionary which needs to be handled in the code.

Looking at the complexity, I thought it would be easier to write a synchronous commmunication.

How to run

Using it is fairly simple:

import streamlit as st
from streamlit_ws_localstorage import injectWebsocketCode, getOrCreateUID

# Main call to the api, returns a communication object
conn = injectWebsocketCode(hostPort='linode.liquidco.in', uid=getOrCreateUID())

st.write('setting into localStorage')
ret = conn.setLocalStorageVal(key='k1', val='v1')
st.write('ret: ' + ret)

st.write('getting from localStorage')
ret = conn.getLocalStorageVal(key='k1')
st.write('ret: ' + ret)

You can use the linode.liquidco.in websocket relay server for testing. Alternately run your websocket relay server from the code in websocket-server/ws_server.py

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_ws_localstorage-1.0.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

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

streamlit_ws_localstorage-1.0.0-py2-none-any.whl (17.0 kB view details)

Uploaded Python 2

File details

Details for the file streamlit_ws_localstorage-1.0.0.tar.gz.

File metadata

File hashes

Hashes for streamlit_ws_localstorage-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1376f12bfb614f874097876697d812ddb53491b850f7ab28d16a52c79b4440aa
MD5 236c33addf93d0d1064c053205a711ff
BLAKE2b-256 0762daa1142a9018ea017f7a8f4d30e939a675761a58e070508d4cc201507cbf

See more details on using hashes here.

File details

Details for the file streamlit_ws_localstorage-1.0.0-py2-none-any.whl.

File metadata

File hashes

Hashes for streamlit_ws_localstorage-1.0.0-py2-none-any.whl
Algorithm Hash digest
SHA256 44dbc48f589babfc511ec04cd3f11a3f0b81a58f7ffcbf87e7c6dd47e7bbb05d
MD5 b86a6ab4deec53c85a6e171fd95242de
BLAKE2b-256 17e509e91ecd5b24946857d63a544f8a301af9f9874b586318149b1d6bd54ee8

See more details on using hashes here.

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