dirdotenv
Like direnv, but works with both .envrc and .env files.
Features
- ✅ Supports
.envfiles with the formatKEY=value - ✅ Supports
.envrcfiles with the formatexport KEY=value - ✅ Shell integration with bash, zsh, fish and pwsh
- ✅ Use
uvx dirdotenvto run it without installation or install easily withuv tool install dirdotenv - ✅ Cross-platform, written in Python
Installation
Using uv
uv tool install dirdotenv
Now it's available as dirdotenv command.
Then update your .bashrc or equivalent:
eval "$(dirdotenv hook bash)"
See Shell Integration for other shells
Using uvx
Run without installation
eval "$(uvx dirdotenv hook bash)"
Using pip
pip install dirdotenv
Development
When developing:
git clone git@github.com:alexeygrigorev/dirdotenv.git
cd dirdotenv
uv sync
# assuming you cloned to ~/git/dirdotenv/
alias dirdotenv="uv run --project ~/git/dirdotenv/ python -m dirdotenv"
eval "$(dirdotenv hook bash)"
Shell Integration
For automatic loading of environment variables when you enter a directory (like direnv), use the hook command:
Bash
Add to your ~/.bashrc:
eval "$(dirdotenv hook bash)"
Zsh
Add to your ~/.zshrc:
eval "$(dirdotenv hook zsh)"
Fish
Add to your ~/.config/fish/config.fish:
dirdotenv hook fish | source
PowerShell
Add to your PowerShell profile (run notepad $PROFILE):
Invoke-Expression ((dirdotenv hook powershell) -join "`n")
How Shell Integration Works
Once configured, the shell integration provides direnv-like behavior:
-
Entering a directory: When you
cdinto a directory with.envor.envrcfiles, the variables are automatically loaded and displayed with a+prefix$ cd myproject dirdotenv: +API_KEY +DATABASE_URL +PORT -
Subdirectory inheritance: Child directories inherit variables from parent directories but can override them
myproject/ .env # API_KEY=parent_value backend/ .env # API_KEY=child_value, DB_HOST=localhost $ cd myproject dirdotenv: +API_KEY $ cd backend dirdotenv: +API_KEY +DB_HOST # API_KEY is overridden, DB_HOST is new -
Leaving a directory: When you leave a directory tree, variables that were set are automatically unloaded and displayed with a
-prefix$ cd .. # leaving myproject tree dirdotenv: -API_KEY -DATABASE_URL -PORT
Advanced usage
Show help
# Display usage information
dirdotenv
dirdotenv --help
Load environment variables from current directory
Note: this is not recommended to use directly - use hooks instead.
# Output export commands for your shell (use --export to prevent accidental exposure)
eval "$(dirdotenv --export)"
Load environment variables from a specific directory
eval "$(dirdotenv /path/to/directory --export)"
Specify shell format
# For bash/zsh (default)
eval "$(dirdotenv --export --shell bash)"
# For fish shell
dirdotenv --export --shell fish | source
# For PowerShell
Invoke-Expression ((dirdotenv --export --shell powershell) -join "`n")
Execute a command with loaded environment variables
# Run a command with the environment variables loaded
dirdotenv --exec python script.py
dirdotenv --exec node app.js
File Format Examples
.env file
OPENAI_API_KEY='my-key'
DATABASE_URL="postgres://localhost/mydb"
API_PORT=8080
# This is a comment
DEBUG=true
.envrc file
export OPENAI_API_KEY='my-key'
export DATABASE_URL="postgres://localhost/mydb"
export API_PORT=8080
# This is a comment
export DEBUG=true
Priority
When both .env and .envrc files exist in the same directory:
- Variables from
.envrcare loaded first - Variables from
.envoverride any duplicate keys from.envrc
Metadata
Release files for dirdotenv 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| dirdotenv-0.0.3.tar.gz | 102.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dirdotenv-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 114.9 kB
Release files / dirdotenv-0.0.3.tar.gz
| Download URL | dirdotenv-0.0.3.tar.gz |
|---|---|
| Size | 102.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2654d7fb0082d27eaf513b72eac782e8ede43a3fa3e685786a0d3ae859fa0a68
|
|
BLAKE2b-256 checksum How to use checksums |
252feae3910fc5a1377b5e707c6f3f1cfe960242093b0d78094c212bbb945773
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Hatch/1.16.2 cpython/3.13.5 HTTPX/0.28.1
|
Release files / dirdotenv-0.0.3-py3-none-any.whl
| Download URL | dirdotenv-0.0.3-py3-none-any.whl |
|---|---|
| Size | 12.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
64e8fec14570dc6cb6741c5825ce3ff4e40cff56ea5891f2699d6bb476fee424
|
|
BLAKE2b-256 checksum How to use checksums |
00f3d838b95fa64828988332c7e888a22afc283a9062d429a6b7e7d268f8faf6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Hatch/1.16.2 cpython/3.13.5 HTTPX/0.28.1
|
Security for dirdotenv 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.