Skip to content

streamlit component that allows you to store and retrieve data in a cookie

License

Notifications You must be signed in to change notification settings

xtliu97/st_cookie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

st_cookie

What

st_cookie is a Python package that allows you to store and retrieve data in a cookie.

Installation

pip install st-cookie

Usage

import

It is recommnend to import st_cookie after st.set_page_config

import streamlit as st

st.set_page_config(layout="wide")
from st_cookie import cookie_manager

Usage 1 (Recommend)

Use context manager cookie_manager.sync() to sync variables to between cookies and session states.

with cookie_manager.sync("my_textinput", "my_number"):
    st.text_input("Enter text", key="my_textinput")
    st.number_input("Enter number", key="my_number")

Usage 2

Use cookie_manager.load_to_session_state() to load all the variables from cookies to session state. Use cookie_manager.update() to update session states to cookies with on_change or on_click callback of streamlit components.

cookie_manager.load_to_session_state()

st.checkbox(
    "enabled",
    key="my_checkbox",
    on_change=lambda: cookie_manager.update("my_checkbox"),
)

About

streamlit component that allows you to store and retrieve data in a cookie

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages