penv
.env loader for Dart

Env File Syntax

penv parses one KEY=value pair per line. This page is the complete reference for what it accepts.

Comments and blank lines

Blank lines, and any line starting with # (after trimming leading whitespace), are ignored:

# This is a comment
   # so is this, despite the leading spaces

API_KEY=abc123

The export prefix

A leading export (or export\t) is stripped, so files meant to be both source-d by a shell and loaded by penv work either way:

export API_KEY=abc123

Quoting

Style Example Behavior
Unquoted PORT=8080 Trailing # comment stripped; ${VAR} expansion applies.
Double-quoted GREETING="hello\nworld" Backslash escapes resolved; ${VAR} expansion applies.
Single-quoted PASSWORD='p@$$w0rd' Taken completely literally — no escaping, no expansion.

Use single quotes whenever a value might contain a literal $ or backslash you don’t want interpreted.

Escape sequences (double-quoted values only)

\n, \t, \r, \", \\, and \$ (a literal $ that survives before variable expansion runs). Any other backslash sequence is left as-is.

Inline comments

Unquoted values have a trailing # comment (space or tab before the #) stripped:

PORT=8080 # default port

parses to PORT = 8080. A # with no preceding whitespace is treated as part of the value, so quote the value if you need a literal #.

Variable expansion

When expandVariables is true (the default), ${OTHER_KEY} inside unquoted or double-quoted values is replaced with the value of OTHER_KEY — first looked up among keys defined earlier in the same file, then falling back to the current process environment. An unresolved reference expands to an empty string.

HOST=example.com
BASE_URL=https://${HOST}/api

BASE_URL parses to https://example.com/api. See Advanced Parsing for a complete example, and Custom Session Store’s neighbor examples in ptgc for a real consumer of this.

Skipped lines

A line with no = at all, or an empty key (a line starting with =), is skipped rather than raising an error — penv is deliberately lenient about stray lines.