Skip to main content

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_data instead of deprecated st.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.toml format

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

  1. Caching Update: Replaced deprecated @st.cache with @st.cache_data for Streamlit 1.18+ compatibility
  2. Dependency Updates: Updated all Python and JavaScript dependencies to latest stable versions
  3. Build System: Migrated from Poetry to UV for faster, more reliable dependency management
  4. Package Format: Updated to PEP 621 compliant pyproject.toml format
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_cookies_manager_v2-0.3.1.tar.gz (311.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamlit_cookies_manager_v2-0.3.1-py3-none-any.whl (556.8 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_cookies_manager_v2-0.3.1.tar.gz.

File metadata

File hashes

Hashes for streamlit_cookies_manager_v2-0.3.1.tar.gz
Algorithm Hash digest
SHA256 ef327bd4b1c74a1c7a77a5769c1fa209adea762fddf9771918efc62306549c84
MD5 53f5824573dbf1da3dba1598e34e2944
BLAKE2b-256 3134ca8563a1766f48aa81c9fe5798edf53ae05409e622c21e61b2f022ec6f46

See more details on using hashes here.

File details

Details for the file streamlit_cookies_manager_v2-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_cookies_manager_v2-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8d7f201fe7af42d5a739472cc7998500fe1aedba24b3418fafdc84466b311df5
MD5 c6a5db1c1e88edcda8296194eac79b4e
BLAKE2b-256 7ed74cc9fead85cc997313e82caa8642693a3c8c00a7721604cf73449c921ab9

See more details on using hashes here.

Supported by

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