liveBook · Manning

.streamlit directory

As explained in Build Python Web Apps with Streamlit

The .streamlit directory is a project directory containing Streamlit configuration files and related settings.

The .streamlit directory keeps Streamlit configuration files such as secrets.toml alongside a project. A common use is storing an API key outside the application code, then reading it through st.secrets. section 9.2.6

Store and use an API key

Create .streamlit/secrets.toml with llm_api_key = "sk-proj-...". Run streamlit run main.py from the directory containing main.py so Streamlit can find .streamlit, then pass st.secrets['llm_api_key'] to the Game instance. section 9.2.6

Treat the directory differently across local development and deployment:

  • During local Docker Compose use, mount .streamlit into the container instead of placing it in the image. section 12.3.5
  • On Elastic Beanstalk, provide secrets.toml through .ebextensions because the deployed application cannot rely on direct filesystem access. section 12.3.5
Listing 9.3 Placing your LLM API key in .streamlit/secrets.toml
llm_api_key = "sk-proj-..."    #1

Inspect the minimal secrets.toml listing to see the plain, non-nested API-key format. section 9.2.6

How Build Python Web Apps with Streamlit covers it

How deep it goes
Explains local lookup, Docker mounting, and Elastic Beanstalk provisioning, without detailing broader Streamlit configuration.
Examples
Uses an LLM API key, a minimal trivia-question app, Docker volume mounts, and an Elastic Beanstalk configuration file.
What it assumes
Assumes a Streamlit app, a main.py entry point, and an API key that the application must access.
What you can do after
Operate/configure a Streamlit app with local secrets and adapt secret provisioning for Docker Compose or Elastic Beanstalk.
How it connects
Connects Streamlit secrets, TOML, Docker Compose, containers, and Elastic Beanstalk deployment.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Python Web Apps with Streamlit. The section links point to the parts of the book it draws on.