dotenvy
A well-maintained, actively developed fork of the dotenv crate for loading .env files in Rust
Repository Health
Technical Analysis
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/EnvMapAPI that parses.envfiles without touchingstd::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
.envfiles - Configurable load sequencing (
InputThenEnv/EnvThenInput) to control override precedence - Reader-based loading from any
io::Readsource, not just files - A
dotenvy_macrocrate providing adotenv!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
.envfile 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.
Used by 17 apps in this directory
claw-code
AI Agents · AI Code Assistants
A Rust-built CLI agent harness for Claude AI with persistent sessions, MCP tool integration, plugin hooks, and multi-provider support — designed to run autonomous coding workflows without human babysitting.
cocoindex
Data Engineering · AI Development
An incremental data indexing engine that keeps AI agent context perpetually fresh by reprocessing only what changed.
CubeSandbox
Developer Tools · Security · AI Agents
Instant, concurrent, hardware-isolated MicroVM sandboxes for AI agents — E2B-API compatible, sub-60ms cold starts, and a built-in zero-trust egress proxy, all self-hostable at scale.
DefGuard
Security · Networking · Authentication
Self-hosted secure remote access that unifies WireGuard VPN, identity management, and connection-level MFA in one open-source platform.
FastGPT
AI Agents · AI Development
Build, debug, and deploy knowledge-based AI agents with a visual workflow editor, RAG retrieval, and support for any OpenAI-compatible LLM.
Fern
Developer Tools
Fern turns a single OpenAPI, AsyncAPI, or Protobuf definition into type-safe SDKs for nine languages and a hosted API documentation site, all from one CLI and one source of truth.
helix-db
Databases
A graph-vector database built from scratch in Rust that unifies graph traversal, vector search, key-value, and relational storage into a single platform for AI applications.
InfluxDB
Databases · Analytics
Open-source time-series database built for real-time ingest, fast SQL queries, and embedded Python automation — powered by Apache Arrow and Parquet.
Latitude
AI Agents · Monitoring
Open-source AI agent monitoring that catches what will break next before your users do.