Literal, lossless .env parsing and editing for Rust.

Built for linters, formatters, editors, scanners, and services. Keeps source text verbatim, maps every token to exact byte spans, and re-parses every edit before returning it.

v1.8.1 #![forbid(unsafe_code)] 0 required deps no_std + alloc MSRV 1.81
Cargo.toml
[dependencies]
adotenv = "1.8.1"

# Optional no_std + alloc core:
# adotenv = { version = "1.8.1", default-features = false }
Shell
cargo add adotenv
3.83x faster
vs. dotenvy (geomean)
20/20 non-empty compact speed wins; 29.5x faster than dotenv-parser
610x fewer
heap allocations vs. dotenvy
30/30 peak-heap & allocation wins; 2.83x lower peak heap
0 deps
Pure safe Rust core
Unconditional #![forbid(unsafe_code)], no file I/O, no env access, no process spawning
100%
Byte-for-byte lossless
Preserves comments, BOM, mixed CRLF/LF, and invalid lines with exact spans
API overview

One parser for tooling, linting, and fast loading

Use lossless Document for editors and linters, or CompactValues when you only need final key-value pairs with minimal heap pressure.

Parse & edit

src/edit.rs
let text = "# app\nexport PORT=8080\nURL=\"${HOST}/api\" # base\n";
let doc = adotenv::parse_strict(text).unwrap();

assert_eq!(doc.get("PORT"), Some("8080"));
assert_eq!(doc.get("URL"), Some("${HOST}/api")); // literal, never expanded
assert_eq!(doc.to_string(), text); // byte-for-byte lossless

let url = doc.get_entry("URL").unwrap();
assert_eq!(url.line(), 3);
assert_eq!(&text[url.value_span().unwrap()], "\"${HOST}/api\"");

// Verified source-preserving edit keeps comments and formatting intact:
let edited = doc.set("URL", "https://example.invalid").unwrap();
assert_eq!(
    adotenv::parse_strict(edited.as_str()).unwrap().get("URL"),
    Some("https://example.invalid")
);
Design guarantees

Built for predictable behaviour on real repositories

Most .env loaders silently mutate process state, discard formatting, or expand shell-like syntax behind your back. adotenv keeps every boundary explicit.

Literal by default

Never expands or executes values silently

Values like ${HOME}, $USER, and command-like text stay literal. Variable resolution, file cascades, process mutation, and command execution live in explicit opt-in APIs or separate crates.

References & resolution →
Byte-for-byte lossless

Exact round-trips for any UTF-8 source

Comments, indentation, quoting, blank lines, invalid statements, a UTF-8 BOM, and mixed CRLF/LF line endings are preserved verbatim.

Parsing & lookup →
Verified edits

Exact byte spans & re-parsed edits

Every token carries a byte span and decoded values map back to source bytes. Edits return source-relative TextEdits and a re-parsed, verified document before returning.

Source-preserving editing →
#![forbid(unsafe_code)]

Zero required runtime dependencies

The core crate forbids unsafe code, supports no_std + alloc, and adds zero required dependencies (only the optional serde feature pulls serde).

Architecture →
5 dialect presets

Portable, Node, Python, Compose & Docker

Switch between Dialect::PORTABLE, NODE_DOTENV, PYTHON_DOTENV, COMPOSE, and DOCKER_RAW without changing files or re-allocating input.

Dialect rules →
Tooling ecosystem

CLI, linter, LSP, config & Figment

Share one parser across adotenv-cli, adotenv-lint, adotenv-lsp, adotenv-process, adotenv-config, and adotenv-figment with versioned JSON report schemas.

CLI & editor tooling →
Benchmarks · v1.8.0

Measured against pinned Rust .env parsers

Content-addressed fixtures from 8 to 100,000 entries on a dedicated quiet Linux x86_64 host, verified from clean commit 28ffe7b.

Parse & load speed

adotenv Parse & load speed vs Rust .env peers Geometric-mean speed across shared non-empty fixtures (v1.8.0, commit 28ffe7b), normalized to adotenv (CompactValues) = 1.00x on a log scale. Lower is faster. adotenv (CompactValues) = 1.00x ← Faster Slower → 0.5x 1x 2x 4x 10x 30x adotenv (CompactEntries) 0.99x adotenv (CompactValues) 1.00x adotenv (BTreeMap) 1.39x dotenv-flow 2.20x dotenv 2.22x dotenvs 2.85x dotenvy 3.83x dotenv-parser 29.5x
adotenv Parse & load speed vs Rust .env peers
Implementation Ratio vs baseline
adotenv (CompactEntries) 0.99x
adotenv (CompactValues) 1.00x
adotenv (BTreeMap) 1.39x
dotenv-flow 2.20x
dotenv 2.22x
dotenvs 2.85x
dotenvy 3.83x
dotenv-parser 29.5x
Geometric-mean speed across shared non-empty fixtures (v1.8.0, commit 28ffe7b), normalized to adotenv (CompactValues) = 1.00x on a log scale. Lower is faster.
Workspace

Seven focused crates, one parser core

Pull only what you need: keep your core dependency tree at zero, or add linting, LSP, CLI, and configuration adapters that agree byte for byte.

Crate Version Role Links
adotenv v1.8.1 Core literal parser, spans, dialects, CompactValues, verified edits, optional load/serde/exec Guide · crates.io
adotenv-cli v1.8.1 Command-line checker, formatter, diff, and JSON/GitHub annotation reporter Guide · crates.io
adotenv-lint v0.3.2 Configurable lint engine with stable diagnostic codes and fix suggestions Guide · crates.io
adotenv-lsp v0.7.2 Language server providing diagnostics, hover, formatting, and quick fixes for editors Guide · crates.io
adotenv-process v1.8.1 Explicit, isolated process environment mutation helpers Guide · crates.io
adotenv-config v0.12.1 Adapter for the Rust config crate Guide · crates.io
adotenv-figment v0.12.2 Provider adapter for Figment Guide · crates.io