penv
.env loader for Dart

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']}');
}

Why penv

  • No dependencies to speak of — reads and parses plain text, nothing else.
  • Real .env syntax — comments, export prefixes, single- and double-quoted values (with backslash escapes in double quotes), inline comments on unquoted values, and ${OTHER_KEY} variable expansion.
  • Typed accessorsgetInt, getDouble, getBool, getString on the plain Map<String, String> penvload returns, with clear FormatExceptions instead of null-check crashes.
  • Required-key validation — pass required: [...] and get one clear MissingRequiredKeysException instead of scattered null checks.
  • Helpful on first run — if the file doesn’t exist, penvload writes 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 like PATH.

Install

dart pub add penv