Handle .env files and per-environment configuration: dotenv format rules, loading with python-dotenv or shell, dev/staging/prod config, and secret hygiene. Triggers when an agent must read, write, load, or debug environment variables or secrets.
./install.sh env-managementname: "env_management" description: "Handle .env files and per-environment configuration: dotenv format rules, loading with python-dotenv or shell, dev/staging/prod config, and secret hygiene. Triggers when an agent must read, write, load, or debug environment variables or secrets."
Give an agent a reliable, verified playbook for environment configuration: write valid .env files, load them in Python or shell, separate dev/staging/prod config, and keep secrets out of repos and logs. Every format claim below was tested against installed python-dotenv.
.env, .env., .env.example, exported vars). Read the current file first; merge edits, never blind-overwrite a .env that may hold live secrets.KEY=value per line, keys in UPPER_SNAKE. All of the following are real, tested behavior:= are tolerated: SPACED = v loads as SPACED=v, but default to no spaces for safety.GREETING="hello world". Single quotes also work. Unquoted values stop at whitespace.# comment, or trailing # comment after an unquoted value (a # inside quotes is kept: HASHED="a # b").export is accepted and stripped: export API_KEY=abc loads as API_KEY=abc.\n escape inside double quotes (verified: expands to a real newline). Single-quoted \n stays literal.OPTIONAL=.python
from dotenv import load_dotenv
load_dotenv() # reads .env in the current working directory
Default load_dotenv() does not override variables already set in the environment (verified). Pass override=True to force file values.
set -a; source .env; set +a exports every var, but verified: it breaks on unquoted values containing spaces (BAZ=hello world → world: command not found). Either quote such values in the file or use export $(grep -v '^#' .env | xargs) for simple value-only files..env.development, .env.staging, .env.production — load the one matching APP_ENV (or the deploy target's own env vars)..env plus per-env overrides applied on top. Always commit a .env.example with placeholder values and a comment per key explaining what it is; real .env files are never committed..env (and .env. except .env.example) to .gitignore, then confirm with git status --porcelain that no .env shows as tracked or staged. Prefer env vars over hardcoded secrets everywhere — code, prompts, and logs..env written or edited must parse before the task is done. Validate with: python3 -c "from dotenv import dotenv_values; print(dotenv_values('.env'))".gitignore covers it (verified via git status), and the exact load call the consumer should use..env before writing — merge, don't clobber.=..env.example committed and real .env ignored, never the reverse.publisher key 2e43c913833850e6d80f939677e3de76e806d47785c0f1caaca90f9d18c98e1e
No ratings yet — be the first to rate it.