Streamlit Cookie Banner Component
A custom Streamlit component to display a basic cookie banner on your Streamlit web application. This component allows you to display a cookie consent message with customizable text and an optional link to a privacy policy or other relevant information.
Installation
You can install this component by adding it to your project and running the following command after packaging it:
pip install streamlit-cookie-banner
Usage
To use the cookie banner in your Streamlit app, you simply import the cookie_banner function from the component and use it within your Streamlit app like this:
import streamlit as st
from streamlit_cookie_banner import cookie_banner
consent = cookie_banner(
banner_text="We use cookies to ensure you get the best experience.",
display=True, # Set to False if you want to hide the banner
link_text="Learn more", # Optional: Link text (e.g., 'Learn more')
link_url="https://your-privacy-policy-url.com", # Optional: URL to your privacy policy
key="cookie_banner" # Optional: A unique key to control re-rendering
)
Use the consent
import streamlit as st
from streamlit_cookie_banner import cookie_banner
consent = cookie_banner(
banner_text="This website uses cookies to improve your experience.",
display=True,
link_text="Read our Privacy Policy",
link_url="https://example.com/privacy-policy",
key="cookie_banner"
)
if consent:
st.write("Thank you for accepting cookies!")
else:
st.write("Please consider accepting cookies to improve your experience.")
Consent is returned as None if user hasn't selected Agree/Disagree, True for Agree & False for Disagree. After selection the value is stored in local session cookies to avoid showing the cookie bar again.
Frontend Assets
The component uses frontend files located in the frontend/public directory. These files are responsible for rendering the banner in the browser. You can edit these to control the styling etc of the banner.
License
This project is licensed under the MIT License. See the LICENSE file for more details.
Contributing
Contributions are welcome! Feel free to open an issue or submit a pull request.
Author
Luke Bowes
Metadata
Release files for streamlit-cookie-banner 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| streamlit_cookie_banner-0.1.0.tar.gz | 5.7 kB | Without provenance | Details for streamlit_cookie_banner-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| streamlit_cookie_banner-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for streamlit_cookie_banner-0.1.0-py3-none-any.whl |
Total release size: 12.7 kB
Security for streamlit-cookie-banner 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.