Skip to main content

Access and save cookies from Streamlit

Project description

Streamlit Cookies Manager

Access and change browser cookies from Streamlit scripts:

import os
import streamlit as st
from streamlit_cookies_manager import EncryptedCookieManager

# This should be on top of your script
cookies = EncryptedCookieManager(
    # This prefix will get added to all your cookie names.
    # This way you can run your app on Streamlit Cloud without cookie name clashes with other apps.
    prefix="ktosiek/streamlit-cookies-manager/",
    # You should really setup a long COOKIES_PASSWORD secret if you're running on Streamlit Cloud.
    password=os.environ.get("COOKIES_PASSWORD", "My secret password"),
)
if not cookies.ready():
    # Wait for the component to load and send us current cookies.
    st.stop()

st.write("Current cookies:", cookies)
value = st.text_input("New value for a cookie")
if st.button("Change the cookie"):
    cookies['a-cookie'] = value  # This will get saved on next rerun
    if st.button("No really, change it now"):
        cookies.save()  # Force saving the cookies now, without a rerun

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

Built Distribution

File details

Details for the file gitarplater_streamlit_cookies_manager-0.2.0.tar.gz.

File metadata

File hashes

Hashes for gitarplater_streamlit_cookies_manager-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3d5c04a434dc5658ee0bcac9acaa4d3054afbdbd00bc46f0ae9af7bb932863dd
MD5 eefd6056c5417a034724404b976a15a2
BLAKE2b-256 2f61039142eccb1c72b01002270116fbbd540b86ceddd00c0585a275f9d92881

See more details on using hashes here.

File details

Details for the file gitarplater_streamlit_cookies_manager-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gitarplater_streamlit_cookies_manager-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 976d348293c7405be9a3d96f9fcb347598d33abae95613127b437a7e2a4e472f
MD5 055253d19914e0653922b2338309ae44
BLAKE2b-256 251c2c535cfabe7550be4910f1bfc4f2891f92967600e228667acc7c9b942c47

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page