dotenv (Rust)
Loads environment variables from a .env file for Rust development and testing
Repository Health
Technical Analysis
dotenv is a Rust port of the Ruby dotenv gem: it reads key-value pairs from a .env file in the current directory (or any parent directory) and merges them into the process’s environment variables, so local development and test runs don’t require exporting secrets or config manually. Calling dotenv::dotenv().ok() at the start of main() is the typical integration point, after which code just reads values via the standard std::env APIs.
The workspace also ships dotenv_codegen, which provides a dotenv! macro that behaves like the standard env! macro but reads from a .env file at compile time, and supports bash-style variable substitution ($VAR, ${VAR}) inside the .env file itself. The project has been in maintenance mode since 2020 (last release v0.15.0), with the community-maintained dotenvy fork now recommended for actively developed use, but the original crate remains widely depended upon.
What You Get
dotenv()to auto-discover and load a.envfile from the current or a parent directoryfrom_filename()/from_path()for loading a specifically named or located env file- Iterator variants (
dotenv_iter,from_path_iter) for inspecting parsed values without mutating the environment - Bash-style
$VAR/${VAR}variable substitution and comment/quoting support in.envparsing - A companion
dotenv_codegencrate providing adotenv!compile-time macro analogous toenv! - An optional
clifeature building a standalonedotenvbinary for shell use
Common Use Cases
- Loading local development secrets (database URLs, API keys) from a
.envfile at the top ofmain() - Configuring integration tests with a
.env.testfile viafrom_filename()without touching the shell environment - Baking configuration into a binary at compile time using the
dotenv!macro instead of a runtime lookup - Sharing a
.env.exampletemplate across a team while keeping actual secrets untracked in git
Under The Hood
Architecture — The workspace splits cleanly into dotenv (the runtime parser/loader in find.rs, parse.rs, iter.rs, errors.rs) and dotenv_codegen/dotenv_codegen_implementation (a proc-macro crate pair implementing the dotenv! macro by shelling out to the same parsing logic at compile time). Tech Stack — Pure Rust, 2018 edition, with almost no dependencies: the core crate only optionally pulls in clap v2 behind a cli feature flag, and tempfile is a dev-only test dependency. Code Quality — Coverage is broad for a small crate: dedicated integration tests exist for filename loading, path loading, child-directory discovery, variable substitution, and iterator behavior (test-variable-substitution.rs, test-child-dir.rs, etc.), tracked with CI and Codecov, though the project has had no commits since mid-2024 and no release since 2020, so it functions as a stable but frozen dependency. API Design — The primary entry point is a single call, dotenv().ok(), with clearly named escape hatches (from_filename, from_path) for non-default cases, keeping the learning curve close to zero and matching the ergonomics of the well-known Ruby/Node dotenv libraries it was modeled on.
Used by 3 apps in this directory
Cryptgeon
File Storage · Security
Self-destructing encrypted notes and files that vanish after viewing — the server never sees your keys.
Laminar
AI Development · Monitoring
Open-source observability platform purpose-built for AI agents — trace, evaluate, debug, and monitor at scale with SQL access and real-time replay.
PostgresML
Databases · AI Development
Run ML training and LLM inference natively inside PostgreSQL with GPU acceleration — no data movement required.