Secrets.toml FileNotFoundError

I am new to streamlit (and toml files!). Working on an app locally on my machine. This uses an API to geocode postcodes. Rather than have the user enter the API into a text input field, I’d like to make use of st.secrets. I have set up a toml file from windows text editor (this is saved with .txt extension, how do I save with .toml extension?). I have put the secrets.toml file within a folder called .streamlit which itself is within a folder containing (the streamlit app file). Despite following the structure, I am getting FileNotFoundError. Would really appreciate a steer to resolve this, thanks.

my folder structure is: (streamlit app)
/ .streamlit/
secrets.toml (saved as txt file though)

I run st.write(st.secrets[‘api_key’]) in, but this prompts the file not found error. I was expecting this to print my api key to the screen (as a test, wont be keeping that line!).

  • Streamlit version: 1.24.0
  • Python version: 3.8.13
  • Using Conda
  • OS version: windows 11 enterprise
  • Browser version: edge 114.0.1823.79

I’m not 100% sure on how to go about creating a toml file so may have done this incorrectly - the process I went about was to open a text file, add in api key using the format from the toml website (e.g. api_key = “some_api_key”, and save-as secrets.toml in the above location.

Hi @Mr.E, and welcome to our forums! :wave:

Make sure that you’re saving it with the .toml extension instead of .txt. To do this, when you click “Save As,” you can write the file name as “secrets.toml.”

I believe this is where your issue lies.



ah @Charly_Wargnier , thanks so much! Apols for the newbie question (!), couldn’t see how to do that in the text editor, but just found I could save as .toml within vscode itself. All sorted and working, thanks again :+1:

1 Like

Glad it fixes it!

Happy Streamlit’in! :balloon:


This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.