dotenvy

A well-maintained, actively developed fork of the dotenv crate for loading .env files in Rust

Library
Cargo
v0.15.7
1,252 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
60 /100 Good
Development Activity 48
Maintenance 40
Community 56
Maturity 56
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
70 /100 Good
Architecture 68
Code Quality 70
Innovation 65
Learning Curve 78

dotenvy is a Rust library for loading environment variables from .env files, built as the actively maintained successor to the abandoned dotenv crate. It is the recommended replacement cited in security advisory RUSTSEC-2021-0141, and provides both a non-modifying API (returning an EnvMap without touching std::env) and a modifying API via the #[dotenvy::load] attribute macro for cases where the process environment itself must be populated before other code runs.

Beyond basic key-value loading, dotenvy supports multiline values, variable substitution, configurable load sequencing (file-then-env or env-then-file), reading from arbitrary io::Read sources, and a companion dotenvy_macro crate for compile-time .env inspection via a dotenv! macro. A small CLI binary is also included for loading an env file before executing another command.

What You Get

  • A non-modifying EnvLoader/EnvMap API that parses .env files without touching std::env
  • A modifying API via the #[dotenvy::load] attribute macro for populating the process environment before an async runtime starts
  • Support for multiline values and variable substitution within .env files
  • Configurable load sequencing (InputThenEnv / EnvThenInput) to control override precedence
  • Reader-based loading from any io::Read source, not just files
  • A dotenvy_macro crate providing a dotenv! compile-time macro for embedding values at build time
  • A small CLI binary that loads an env file before executing a specified command

Common Use Cases

  • Loading local development configuration (database URLs, API keys) from a .env file without committing secrets to source control
  • Supporting dev/prod configuration switching by loading different env files per environment
  • Populating environment variables for a spawned child process that reads from std::env
  • Compile-time embedding of configuration values via the dotenv! macro for values that never change at runtime

Under The Hood

Architecture - dotenvy is organized as a small Cargo workspace with a core dotenvy crate plus companion dotenvy-macros/dotenv_codegen crates and a thin CLI binary. The core crate splits parsing (parse.rs), iteration over key-value pairs (iter.rs), and error types (err.rs) from the public lib.rs surface, which exposes an EnvLoader builder that either returns a standalone EnvMap (non-modifying) or, via the #[dotenvy::load] attribute macro, writes directly into std::env before other code (including async runtimes) starts. Tech Stack - Pure Rust with minimal dependencies; the CLI binary and macro support are gated behind optional Cargo features (cli, macros) using clap for argument parsing, keeping the core library dependency-free for consumers who only need file parsing. Code Quality - The codebase is compact (~1,400 lines across four core source files) with #![deny(clippy::uninlined_format_args, clippy::wildcard_imports)] enforced at the crate root; unit tests exist in the parser and iterator modules but coverage is modest relative to the surface area, and error types are deliberately informative (carrying file path and variable name) rather than opaque. API Design - The library favors an ergonomic, builder-style EnvLoader with clear non-modifying vs. modifying entry points, sensible defaults (./​.env, non-overriding), and thorough README-level documentation of configuration options, making it easy to adopt with minimal boilerplate.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers