| Crates.io | dotenvx |
| lib.rs | dotenvx |
| version | 0.2.2 |
| created_at | 2025-11-26 08:41:46.725156+00 |
| updated_at | 2025-11-26 14:24:01.50189+00 |
| description | A secure environment variable management tool with built-in encryption |
| homepage | |
| repository | https://github.com/fabianopinto/dotenvx |
| max_upload_size | |
| id | 1951128 |
| size | 176,303 |
A secure environment variable management tool with built-in encryption, written in Rust. This is a complete reimplementation of dotenvx with performance improvements and memory safety guarantees.
${VAR:-default} syntax.env filesbrew tap fabianopinto/tap
brew install dotenvx
cargo install dotenvx
git clone https://github.com/fabianopinto/dotenvx
cd dotenvx
cargo install --path .
Download pre-built binaries from the releases page.
dotenvx keypair
This generates a public/private keypair for encryption.
# Create a .env file
echo "DATABASE_PASSWORD=super_secret" > .env
# Encrypt it
dotenvx encrypt
Your .env file now contains encrypted values:
#/-------------------[DOTENV_PUBLIC_KEY]--------------------/
#/ public-key encryption for .env files /
#/ [how it works](https://dotenvx.com/encryption) /
#/----------------------------------------------------------/
DOTENV_PUBLIC_KEY="034af93e..."
DATABASE_PASSWORD="encrypted:BG8M6U+GKJGwpGA..."
The private key is stored in .env.keys (automatically added to .gitignore).
dotenvx run -- your-command
Environment variables are automatically decrypted and injected.
keypair - Generate a new keypairdotenvx keypair
Output:
DOTENV_PUBLIC_KEY="034af93e93708b994c10f236c96ef88e..."
DOTENV_PRIVATE_KEY="ec9e80073d7ace817d35acb8b7293cbf..."
encrypt - Encrypt environment variables# Encrypt default .env file
dotenvx encrypt
# Encrypt specific file
dotenvx encrypt -f .env.production
# Encrypt specific keys only
dotenvx encrypt -K API_KEY -K DATABASE_PASSWORD
# Exclude certain keys
dotenvx encrypt -e DEBUG -e LOG_LEVEL
decrypt - Decrypt environment variables# Decrypt default .env file
dotenvx decrypt
# Decrypt specific file
dotenvx decrypt -f .env.production
set - Set an environment variable (encrypted by default)# Set encrypted variable
dotenvx set API_KEY "sk_live_123456"
# Set plain text variable
dotenvx set DEBUG "true" --plain
# Set in specific file
dotenvx set DATABASE_URL "postgres://..." -f .env.production
get - Get an environment variable value# Get specific variable
dotenvx get API_KEY
# Get all variables
dotenvx get
# From specific file
dotenvx get DATABASE_URL -f .env.production
ls - List all .env files# List in current directory
dotenvx ls
# List in specific directory
dotenvx ls /path/to/project
run - Run command with environment variables# Run with default .env
dotenvx run -- node server.js
# Run with specific files (last wins)
dotenvx run -f .env -f .env.local -- python app.py
# Override existing environment variables
dotenvx run --overload -- ./my-app
printenv - Print environment variables for shell evaluation# Print all variables in bash format (default)
dotenvx printenv
# Print from specific file
dotenvx printenv -f .env.production
# Print from multiple files (last wins)
dotenvx printenv -f .env -f .env.local
# Use with eval to set environment variables
eval "$(dotenvx printenv)"
# Output in different formats
dotenvx printenv --format bash
dotenvx printenv --format fish
dotenvx printenv --format powershell
dotenvx printenv --format json
The printenv command is quiet by default, making it suitable for shell evaluation:
# Bash/Zsh
eval "$(dotenvx printenv)"
# Fish
dotenvx printenv --format fish | source
# PowerShell
Invoke-Expression (dotenvx printenv --format powershell)
.env file.env.keys (gitignored)encrypted: prefix.env.keys, environment variable, or custom pathproject/
├── .env # Public key + encrypted values (committed)
├── .env.keys # Private keys (gitignored)
├── .env.production # Production environment
└── .env.keys # Production keys (deploy separately)
Add to your Cargo.toml:
[dependencies]
dotenvx = "0.1"
Example:
use dotenvx::crypto::{Keypair, encrypt, decrypt};
use dotenvx::parser::DotenvParser;
fn main() {
// Generate keypair
let keypair = Keypair::generate();
// Encrypt a value
let encrypted = encrypt("secret", &keypair.public_key()).unwrap();
// Decrypt a value
let decrypted = decrypt(&encrypted, &keypair.private_key()).unwrap();
// Parse .env file
let mut parser = DotenvParser::new();
parser.parse_with_processing("KEY=value\nURL=$KEY/path").unwrap();
}
.env file format# Comments are supported
KEY=value
export EXPORTED_KEY=value
# Quotes (single, double, or none)
SINGLE='value'
DOUBLE="value"
UNQUOTED=value
# Variable expansion
DATABASE_URL=postgres://${DB_HOST:-localhost}/${DB_NAME}
# Command substitution
CURRENT_USER=$(whoami)
BUILD_TIME=$(date +%s)
# Encrypted values
API_KEY="encrypted:BG8M6U+GKJGwpGA42ml2erb9..."
# Public key (added automatically)
DOTENV_PUBLIC_KEY="034af93e93708b994c10f236..."
.env.keys file format#/------------------!DOTENV_PRIVATE_KEYS!-------------------/
#/ private decryption keys. DO NOT commit to source control /
#/ [how it works](https://dotenvx.com/encryption) /
#/----------------------------------------------------------/
# .env
DOTENV_PRIVATE_KEY=ec9e80073d7ace817d35acb8b7293cbf...
# .env.production
DOTENV_PRIVATE_KEY_PRODUCTION=1fc1cafa954a7a2bf0a6fbff...
.env.keys - Add to .gitignore immediatelyCompared to the Node.js version:
cargo build --release
# Run all tests
cargo test
# Run with output
cargo test -- --nocapture
# Run specific test
cargo test test_encrypt_decrypt
# Format code
cargo fmt
# Lint
cargo clippy -- -D warnings
cargo install cargo-tarpaulin
cargo tarpaulin --out Html
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Licensed under either of:
at your option.