Access and save cookies from Streamlit - Modernized fork with st.cache_data fix, uv package manager, and updated Node dependencies
Project description
Streamlit Cookies Manager v2
Note: This is a modernized fork of the original streamlit-cookies-manager by Tomasz Kontusz. The core functionality and most of the codebase remains his work. This fork updates the package for Streamlit 1.18+ compatibility and modern Python tooling.
What's New in This Fork
- ✅ Compatible with Streamlit 1.18+ - Uses
st.cache_datainstead of deprecatedst.cache - ✅ Updated Dependencies - All dependencies updated to latest stable versions
- ✅ Modern Build System - Switched from Poetry to UV (by Astral) for faster dependency management
- ✅ Python 3.9+ Support - Tested with Python 3.9, 3.10, 3.11, 3.12, and 3.13
- ✅ PEP 621 Compliant - Uses modern
pyproject.tomlformat
Installation
From PyPI
pip install streamlit-cookies-manager-v2
# Or using UV
uv pip install streamlit-cookies-manager-v2
From GitHub (Development)
pip install git+https://github.com/JohnDoeData/streamlit-cookies-manager.git
# Or using UV
uv pip install git+https://github.com/JohnDoeData/streamlit-cookies-manager.git
Usage
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="myapp/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
Features
Basic Cookie Manager
from streamlit_cookies_manager import CookieManager
cookies = CookieManager()
if not cookies.ready():
st.stop()
# Get a cookie
value = cookies.get('cookie_name')
# Set a cookie
cookies['cookie_name'] = 'cookie_value'
# Delete a cookie
del cookies['cookie_name']
# Save immediately (without waiting for rerun)
cookies.save()
Encrypted Cookie Manager
from streamlit_cookies_manager import EncryptedCookieManager
cookies = EncryptedCookieManager(
password="your_secret_password",
prefix="myapp/", # Optional: prefix for all cookies
)
# All operations are the same as CookieManager
# but cookie values are automatically encrypted/decrypted
Requirements
- Python 3.9+
- Streamlit 1.18.0+
- cryptography
Development
This project uses UV for dependency management:
# Clone the repository
git clone https://github.com/JohnDoeData/streamlit-cookies-manager.git
cd streamlit-cookies-manager
# Create virtual environment
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
uv pip install -e .
# Build JavaScript component
cd streamlit_cookies_manager
npm install
npm run build
Changes from Original
- Caching Update: Replaced deprecated
@st.cachewith@st.cache_datafor Streamlit 1.18+ compatibility - Dependency Updates: Updated all Python and JavaScript dependencies to latest stable versions
- Build System: Migrated from Poetry to UV for faster, more reliable dependency management
- Package Format: Updated to PEP 621 compliant
pyproject.tomlformat - Version: Continuing from 0.3.1 to show continuity from the original project
Credits
Original Author: Tomasz Kontusz - streamlit-cookies-manager
Current Maintainer: JohnDoeData
This fork is maintained to ensure compatibility with modern Streamlit versions. The majority of the codebase and functionality was created by the original author.
License
Apache-2.0 (same as original)
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters