Secrets file not found. Expected at: /opt/render/project/src/.streamlit/secrets.toml

I have API key for my webapp which I saved and stored in .streamlit/secrets.toml ( which was not uploaded ofcourse in my github repo synced with the render webservice instance). But under the “Secrets” section for deployment of the webservice, it doesn’t allow me to define this way and I can only create it at root which is not as per the standard laid out by streamlit framework:

Can you please help me to how to workaround in this case? ( i.e. with streamlit )

Thanks a lot!


Current Error as I had no option but to add secrets at the root:

Hi there,

Thanks for reaching out.

I’m not familiar with Streamlit or its secret management, but it feels like there are a couple of ways to resolve this:

  • If all your secrets are root-level in the secrets.toml it seems you can reference them through environment variables in your code. You would update your code to access the secrets like os.environ["secret_key_name"] and then add your secrets as environment variables on the “Environment” tab of your service.

  • Alternatively, you may be able to use the secrets.toml by creating a secret file (again on the “Environment” tab of your service) and copy it to where it needs to as part of your Build Command, maybe something like.

    mkdir .streamlit; cp /etc/secrets/secrets.toml ./.streamlit/; pip install -r requirements.txt

Hope that helps


This was super helpful! Thanks a ton @al_ps ! :smile:

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