Continue Discussion 18 replies
April 2021

mw0

My top feature request for several months. Real glad to see this. Thanks!

April 2021

htsnet

great improvement!

June 2021

aktham.momani

Great feature. Thanks for the support Streamlit’s Team :rocket::rocket:

I have one password protected xlsx file, so how can I set (st.secrets)?

xlsx password=“xxxx”

file.load_key(password=“xxxx”) # Use password (Normal).
file.load_key(st.secrets.???) # Use Secrets

Thank you

Regards,
Aktham

June 2021

aktham.momani

After I saw st.secrets is not hashable · Issue #3398 · streamlit/streamlit · GitHub I managed to solve my issue.

Thank you

September 2021

rchak007

this was perfect on how to use secrets for the .env!

December 2021

Rami

Hi Everyone,

For the first time, i am trying to connect postgres DB using st.secrets[“postgres”] and end up with invalid directory. Not sure why its saying file not found even though file exists in the look up directory

here is my secrets file structure in vscode on windows
C:\Users\E57036\Desktop\Python_Work\Streamlit_Dashboard.streamlit\secrets.toml

[
postgres
]
host=""
port=
dbname=""
username=""
password=""

here is the code.

import streamlit as st
import psycopg2

def init_connection():
return psycopg2.connect(**st.secrets[“postgres”])

after running my file via streamlit run or as a python file, i am getting file not found error
FileNotFoundError: [Errno 2] No such file or directory:

‘C:\Users\E57036\Desktop\Python_Work\Streamlit_Dashboard\.streamlit\secrets.toml’

1 reply
July 2022 ▶ Rami

Sinakian

@Rami Dear could you solve? I have difficulty to connect it via secrets.

January 2023

ansgargw

there might be a bug when reading TOML:
I could verify that the secrets.toml file is only read correctly if either in a .streamlit folder under the app.py, or if the .streamlit folder is under the user’s home directory then the error happens if there are sections in the TOML file. Only key=“value” pairs above a bracket line are read, then the parser stops at the bracket to read any key value pairs below. I think the TOML parser is defective.

1 reply
January 2023 ▶ ansgargw

asehmi Streamlit Creator

FYI, in case it’s helpful, you should put singular values in your toml file above key group values, otherwise those singular values will be combined into the key group immediately above. Also the secrets.toml file is only special because it’s available via the Streamlit API and protected in Streamlit Cloud. Otherwise, you can create your own toml files and access them using the toml python package. E.g. for general config (not secrets!), I often do this:

import os
import toml

dir = os.path.abspath(os.path.dirname(__file__))
if os.path.isfile(os.path.join(dir, 'custom_config.toml')):
    service_settings = toml.load(os.path.join(dir, 'custom_config.toml'))
else:
    service_settings = toml.load(os.path.join(dir, 'default_config.toml'))

So, if I’m sharing code with collaborators or on GitHub, I can include the default_config.toml and not my custom_config.toml.

May 2023

vitalyis

Hey,

I’ve run through the docs but here’s the case. What if I have a json file with my Google Cloud credentials that don’t want to keep on a Git or a server but want to store as a secret? It seems like Streamlit Secrets doesn’t support multi-line TOML format, does it?

The Qs is - how can I assign json’s content to a variable and store it as a multi-line out there in the Secret box?

Thanks,
V

1 reply
May 2023 ▶ vitalyis

Goyo

Open the json file in a text editor, copy the text and paste it in the appropriate place inside the secrets box.

1 reply
May 2023 ▶ Goyo

vitalyis

This would have been too easy, but Streamlit doesn’t like my TOML syntax. I’ve tried both these “” and ‘’’ for multi-line

1 reply
May 2023 ▶ vitalyis

Goyo

Your TOML syntax may be wrong. Did you try feeding it directly to a TOML parser? The delimiters are definitely wrong, but they are not displayed as pre-formatted, so it may be just the discuss editor trying to be helpful (and failing).

August 2024

analytics-automation

Does anyone have any more insight here. If the secret changes, the app can re-rerun but streamlit does not capture the new secret causing the app not to work. Why doesn’t streamlit reboot itself and or how can we automate the reboot so it does capture a changed in secrets.

August 2024

PaulHelmick

Is it a correct understanding that Streamlit on Replit does NOT use the new Replit Secrets feature - and that you have to do it via this .toml file?

1 reply
August 2024 ▶ PaulHelmick

blackary Streamlit Team Member

If you are using st.secrets, it will look for a file at .streamlit/secrets.toml. My guess is that if you create such a .toml file, it will work fine, but you are also welcome to use replit’s built-in secrets, and just access them with os.genenv

November 2024

Fuad

Unfortunately server doesnt see any secret keys that uploaded via settings menu. i can run my app locally perfectly. but i get ‘key error’ in logs when running my app. i tried to print out all keys saved in app settings it doesnt print out anything rather empty.

March 6

Sietse

I am looking for a way to set secrets in an app I deploy to an Azure server, i.e. the secrets should be accessible for both local development and the production server. I use the Azure Key Vault. Is there a way to set the Streamlit secrets without creating a file in the process (which would decrease security)? So far I have found this:

from streamlit.runtime.secrets import secrets_singleton
secrets_singleton._maybe_set_environment_variable("name", "value")

Not sure if this is the intended use, since you access protected attributes.