liveBook · Manning

.env file

As explained in Build Financial Software with Generative AI (From Scratch)

An .env file is a conventionally named environment file containing application configuration values as environment-variable assignments.

An .env file stores configuration as environment-variable assignments, such as database usernames and passwords. Moving these values out of application code reduces security exposure and makes server changes easier to maintain. section 3.7

Use an environment file with practical safeguards:

  • Reference it from Docker Compose with the env_file directive. section 3.7
  • Keep sensitive files out of source control, commonly through Git ignore rules. section 3.7
  • Document required variables and setup steps so new instances and team members can configure the system reliably. section 3.7
  • Treat the filename as flexible: .env is common, but meaningful alternatives such as .sql_server.conf or webapp.env also work. section 3.7
POSTGRES_USER=postgres
POSTGRES_PASSWORD=secret

Shows the compact assignment format used for PostgreSQL configuration values. section 3.7

  postgres:
    build: 
      context: ./db
      dockerfile: Dockerfile
    env_file:
      - ./.sql_server.conf

Connects an environment file to a Docker Compose service through env_file. section 3.7

import os
…
POSTGRES_USER = os.getenv("POSTGRES_USER")
POSTGRES_PASSWORD = os.getenv("POSTGRES_PASSWORD")
…
DATABASE_URL = f"dbname={POSTGRES_USER} user={POSTGRES_USER}
➥ password={POSTGRES_PASSWORD} host=postgres port=5432"

Shows application code reading the variables and assembling a database connection string. section 3.7

How Build Financial Software with Generative AI (From Scratch) covers it

How deep it goes
Defines assignments, Docker wiring, naming conventions, and documentation needs, but does not detail a complete file-format specification.
Examples
Uses PostgreSQL assignments, Docker env_file wiring, and Python os.getenv calls to build a database connection string.
What it assumes
Assumes basic configuration and source-control awareness while introducing environment variables and Docker's env_file mechanism.
What you can do after
Operate/configure a Dockerized application by externalizing settings and supplying them through an environment file.
How it connects
Connects environment variables with Docker Compose, Git, source control, database credentials, and application configuration.

Also explained in

Compare how 4 books explain .env file →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Financial Software with Generative AI (From Scratch). The section links point to the parts of the book it draws on.