dotenv module
Read .env-style files into a map. Handles KEY=value, quoted values ("...", '...'), export KEY=value, comments, and blank lines.
import "dotenv" as dotenv;
var env = dotenv.load_or_empty(".env");
print(env.DATABASE_URL);
print(env.API_KEY);
API
| Function | Description |
|---|---|
dotenv.parse(text) → map | Parse a .env-style string into a key/value map. |
dotenv.load(path) → map | Read the file, then parse. Throws if missing. |
dotenv.load_or_empty(path) → map | Same, but returns an empty map if the file is missing. Useful for optional local overrides. |
Supported syntax
KEY=value— bare value, trims surrounding whitespace.KEY="quoted value"/KEY='literal'— quoted forms (no escape expansion in v1).export KEY=value— bash-styleexportprefix is stripped.# comment— full-line comments and blank lines are ignored.
Not supported
- Shell-style variable interpolation (
$VARand the brace form). - Backslash escape sequences inside quoted values.
- Multi-line values.
See also
sys— read process env viasys.env(). Layering.envover real env is a common pattern.