penv
A tiny, dependency-light .env loader for Dart, with typed accessors and clear, actionable errors.
One file, one function call, no build step — ptgc uses it for its own TelegramClient.fromEnv(), and it works just as well standalone.
import 'package:penv/penv.dart';
void main() {
final env = penvload('.env');
final port = env.getInt('PORT', defaultValue: 8080);
print('Starting on port $port with key ${env['API_KEY']}');
}
Getting Started
Install the package and load your first .env file.
Examples
Four runnable programs covering parsing, overlays, and async loading.
API Reference
penvload, penvloadOrNull, penvloadAsync, and the typed accessors.
FAQ
Common questions about required keys, expansion, and process env overlays.
Why penv
- No dependencies to speak of — reads and parses plain text, nothing else.
- Real
.envsyntax — comments,exportprefixes, single- and double-quoted values (with backslash escapes in double quotes), inline comments on unquoted values, and${OTHER_KEY}variable expansion. - Typed accessors —
getInt,getDouble,getBool,getStringon the plainMap<String, String>penvloadreturns, with clearFormatExceptions instead of null-check crashes. - Required-key validation — pass
required: [...]and get one clearMissingRequiredKeysExceptioninstead of scattered null checks. - Helpful on first run — if the file doesn’t exist,
penvloadwrites a placeholder template for you (configurable) rather than just throwing. - A process-environment overlay — let real deployment env vars override values checked into
.env, without pulling in unrelated system variables likePATH.
Install
dart pub add penv
- Package: penv on pub.dev
- Repository: psdkjoon/penv
- License: MIT
- Requires: Dart SDK
^3.5.0