Skip to content

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

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

5 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

See demo.py for a brief example.v

import

import streamlit as st
import st_cookie

Usage 1 (Recommend)

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

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

Usage 2

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

st_cookie.apply()

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

About

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

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages