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

Video demo

https://user-images.githubusercontent.com/544881/185042658-43dd3c58-a086-4457-a042-9d4d895e34ba.mp4

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.1.tar.gz (4.6 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.1-py2-none-any.whl (18.3 kB view details)

Uploaded Python 2

File details

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

File metadata

File hashes

Hashes for streamlit_ws_localstorage-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ec259ed8bcab6e7c1cee32ff96dca9d0060aa7cb8ac50adfe626c60af73bf0d9
MD5 3664ba3a0508b643fd1ac27baca9d34b
BLAKE2b-256 d8105f6e399c46def897deb0fe89d8802838ace4d70f279b5a8957e95f0c388e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for streamlit_ws_localstorage-1.0.1-py2-none-any.whl
Algorithm Hash digest
SHA256 95a2de83cde525c06b3e435ba95319daa3863c64c0c5c43bd9f3acfa6c5c5b83
MD5 4f2f89a133ff0737e6f26b8111bc2049
BLAKE2b-256 c1ce56c3d07d93e1a1f146b1826fb851f09fd9c18ca21f034ef61186c5a2b5f6

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