跳转到主要内容

从Streamlit访问和保存Cookies

项目描述

Streamlit Cookies Manager

从Streamlit脚本访问和更改浏览器Cookies

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="ktosiek/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

项目详情


下载文件

下载适合您平台的文件。如果您不确定要选择哪一个,请了解更多关于安装包的信息。

源分发

streamlit-cookies-manager-0.2.0.tar.gz (680.1 kB 查看哈希值)

上传时间:

构建分发

streamlit_cookies_manager-0.2.0-py3-none-any.whl (691.0 kB 查看哈希值)

上传时间: Python 3

支持者:

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面