CLI to manage environment variables. This tool was created to simplify working with multiple .env files across different projects and environments (development, staging, and local).
Installation
To install the package, simply run:
pip install envm
Commands
save
Save the current environment file to the environments database. By default, it looks for a .env
file in the current directory.
Options:
--envfile
: Specify a different environment file name (default: .env
)
--overwrite/--no-overwrite
: Overwrite existing environment if it exists (default: false)
$ envm save users.dev
$ envm save users.dev --envfile .env.prod
$ envm save users.dev --overwrite
ls
List all your saved environment files. Shows a count of total environments at the end.
$ envm ls
use
Create an environment file in the current directory from a saved environment. By default, it creates a .env
file.
Options:
--envfile
: Specify a different output file name (default: .env
)
--overwrite/--no-overwrite
: Overwrite existing file if it exists (default: false)
--direnv
: Generate .envrc
file for automatic environment loading with direnv
$ envm use users.dev
$ envm use users.dev --envfile .env.prod
$ envm use users.dev --overwrite
$ envm use users.dev --direnv
delete
Delete a saved environment file. Use --force
to skip confirmation:
$ envm delete users.dev
$ envm delete users.dev --force
Enable Shell Completion
Enable autocompletion for your environment variable files
zsh
curl https://raw.githubusercontent.com/emmanueloctavi0/envm/refs/heads/main/src/completion/envm_complete.zsh >> ~/.zshrc
bash
curl https://raw.githubusercontent.com/emmanueloctavi0/envm/refs/heads/main/src/completion/envm_complete.bash >> ~/.bashrc
Automatic Environment Loading with direnv
For automatic loading/unloading of environment variables when entering/leaving directories, use the --direnv
flag with the use
command.
What is direnv?
direnv automatically loads environment variables based on the current directory. Variables are loaded when you enter a directory and unloaded when you leave it.
Quick Setup
$ envm use users.dev --direnv
$ cd /your/project
$ echo $DATABASE_URL
$ cd /another/project
$ echo $DATABASE_URL
Manual direnv Setup
If you prefer to set up direnv manually:
-
Install direnv:
sudo apt install direnv
brew install direnv
-
Add hook to your shell:
eval "$(direnv hook bash)"
eval "$(direnv hook zsh)"
direnv hook fish | source
-
Restart your terminal and use:
$ envm use users.dev --direnv
$ direnv allow
Benefits of direnv Integration
- ✅ Automatic: Variables load/unload when entering/leaving directories
- ✅ Isolated: Each project has its own environment scope
- ✅ Secure: Requires explicit permission per directory
- ✅ Standard: Uses industry-standard tooling
- ✅ Team-friendly:
.envrc
files can be shared with your team