registry
@automindzsheets 01–77shadcn 4.x
SHEET 66

Env Config (Python)

item / server / config

One MissingEnvError naming every missing required var at once, blank counts as missing, and capability flags that turn a feature off instead of crashing the process.

type
item
files
2
registry deps
none
npm deps
none

installs

  • ~/backend/env_config.py
  • ~/backend/tests/test_env_config.py
  • Reads env only when load() runs — never at import
  • One MissingEnvError lists every missing required var at once, sorted, names only
  • A capability flag degrades to False instead of raising; missing_for(flag) names what is still unset

Call env = env_config.load(required=[...], optional={...}, flags={"linear": ["LINEAR_CLIENT_ID", ...]}) once at startup — it reads the process environment at call time, never at import. env.DATABASE_URL for every required or optional name, env.flags.linear is True only when every var for that flag is set, and env.missing_for("linear") returns the names still unset, safe to put in a 503 body. A missing required var raises one MissingEnvError listing every missing name, sorted, names only — no value ever reaches the message, so it is safe in a crash log. A blank string counts as missing. as_int and as_bool coerce an optional value and raise with the var's name on a bad one. Does not parse .env files — the runtime already loads env into the process.

Variations

one state per section

No previews for this item yet.