| icon | lucide/square-terminal |
|---|
python-dotenv includes a dotenv CLI for managing .env files from the
terminal.
The CLI requires the click package. Install it with the cli extra:
=== "pip"
```shell
pip install "python-dotenv[cli]"
```
=== "uv"
```shell
uv add "python-dotenv[cli]"
```
Verify the installation by checking the version:
dotenv --version!!! info
The CLI can also be invoked as a Python module: `python -m dotenv`
Use set, get, and unset to manage key-value pairs:
dotenv set USER foo
dotenv set EMAIL foo@example.org
dotenv get EMAIL
dotenv unset EMAILSee CLI Reference for options such as --quote and
--export.
Load environment variables from .env and execute a command:
dotenv run -- python app.pyBy default, .env values override existing environment variables. Use
--no-override to keep existing values. See CLI
Reference for details.
List values in a format suitable for sourcing in a shell:
dotenv list --format=exportOther formats include simple, json, and shell. See CLI
Reference for all options.
Use -f to target a specific file (default is .env in the current directory):
dotenv -f .env.production list
dotenv -f .env.production run -- python app.pySee CLI Reference for all commands, options, and exit codes.