New Component: st-cookie

st-cookie

What

st-cookie is a Python package that allows you to store and retrieve data in cookie easily.

Repo: GitHub - xtliu97/st_cookie: streamlit component that allows you to store and retrieve data in a cookie

Installation

pip install "st-cookie>=1.0"

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"),
)
2 Likes

This is interesting! I’m curious to learn more about the specific use cases for this package, especially considering that Streamlit Authenticator and the recently introduced official authentication methods can handle authentication.

Additionally, are there any limitations on the amount of data that can be stored in cookies? How does the package manage situations where those limits are exceeded?