Skip to main content

dotenv CLI

Dotenv-CLI is a simple package that provides the dotenv command. It reads the .env file from the current directory puts the contents in the environment and executes the given command.

dotenv supports alternative .env files like .env.development via the -e or --dotenv parametes.

dotenv provides bash completion, so you can use dotenv like this:

$ dotenv make <TAB>
all      clean    docs     lint     release  test

Install

Using PyPi

dotenv-cli is available on PyPi, you can install it via:

$ pip install dotenv-cli

On Debian and Ubuntu

Alternatively, you can install dotenv-cli on Debian based distributions via:

# apt-get install python3-dotenv-cli

Usage

Create an .env file in the root of your project and populate it with some values like so:

SOME_SECRET=donttrythisathome
SOME_CONFIG=foo

Just prepend the command you want to run with the extra environment variables from the .env file with dotenv:

$ dotenv some-command

and those variables will be available in your environment variables.

Rules

The parser understands the following:

  • Basic unquoted values (BASIC=basic basic)
  • Lines starting with export (export EXPORT=foo), so you can source the file in bash
  • Lines starting with # are ignored (# Comment)
  • Empty values (EMPTY=) become empty strings
  • Inner quotes are maintained in basic values: INNER_QUOTES=this 'is' a test or INNER_QUOTES2=this "is" a test
  • White spaces are trimmed from unquoted values: TRIM_WHITESPACE= foo and maintained in quoted values: KEEP_WHITESPACE=" foo "
  • Interpret escapes (e.g. \n) in double quoted values, keep them as-is in single quoted values.

Example .env file:

BASIC=basic basic
export EXPORT=foo
EMPTY=
INNER_QUOTES=this 'is' a test
INNER_QUOTES2=this "is" a test
TRIM_WHITESPACE= foo
KEEP_WHITESPACE="  foo  "
MULTILINE_DQ="multi\nline"
MULTILINE_SQ='multi\nline'
MULTILINE_NQ=multi\nline
#
# some comment

becomes:

$ dotenv env
BASIC=basic basic
EXPORT=foo
EMPTY=
INNER_QUOTES=this 'is' a test
INNER_QUOTES2=this "is" a test
TRIM_WHITESPACE=foo
KEEP_WHITESPACE=  foo
MULTILINE_DQ=multi
line
MULTILINE_SQ=multi\nline
MULTILINE_NQ=multi\nline

Metadata

Release files for dotenv-cli 3.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dotenv-cli 3.0.1
File Size Uploaded
dotenv-cli-3.0.1.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dotenv-cli 3.0.1
File Interpreter ABI Platform
dotenv_cli-3.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.0 kB

Release files / dotenv-cli-3.0.1.tar.gz

Download URL dotenv-cli-3.0.1.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
9fd86a964d501b5c26ef1c31a1d1a9be572227eb03d43656c6b2d8451c1275cc
BLAKE2b-256 checksum
How to use checksums
7f5811357c948b118b550c9b4239f1754887038c2556adfbb42bdb17538c2b7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.10.5

Release files / dotenv_cli-3.0.1-py3-none-any.whl

Download URL dotenv_cli-3.0.1-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b3e406fe0a0833c701c2dca261b5c40a380b9fe8e75af41ffd059bf599e99323
BLAKE2b-256 checksum
How to use checksums
b23a4ad76d494e70d2573b05a2d6a1ca49a3cbeb5804047ed726fc9c83b1dc8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.10.5

Release history Release notifications | RSS feed

3.4.1

2 release files

3.3.1

2 release files

3.3.0

2 release files

3.2.2

2 release files

3.2.1

2 release files

3.2.0

2 release files

3.1.1

2 release files

3.1.0

2 release files

This release

3.0.1 This release

2 release files

3.0.0

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page