When using streamlit app, how to manage secrets? It is quite easy to use st.secrets
function.
when running your Streamlit app locally, you can store secrets in a .streamlit/secrets.toml file. Streamlit uses TOML (Tom’s Obvious, Minimal Language) format for the secrets file, not YAML. Here’s how you can set it up:
Step 1: Create the Secrets File
Create a file named secrets.toml inside a .streamlit folder at the root of your project directory. Your project structure should look something like this:
your_project/ |
Step 2: Add Your Secrets to the File
In secrets.toml, you can add your secrets like this:
# .streamlit/secrets.toml |
Step 3: Access the Secrets in Your Streamlit App
In your Streamlit script (your_script.py), you can access these secrets using st.secrets. For example:
import streamlit as st |
for example, if we have a html code to render, we can use the secrets this way:
import streamlit as st |