Home

Awesome

Python Dot Env Handler

Shell Command and Library to write and read .env like files.

Latest Version Build Status Coverage Status

.env files are commonly used with Procfile-based apps.

Usage

Shell

Inspect file

$ dotenv
FOO: bar
Bar: baz

Get value for key

$ dotenv FOO
FOO: bar

Set value for key

$ dotenv FOO baz
FOO: baz

As a library

>>> from dotenv import Dotenv
>>> dotenv = Dotenv('/path/to/.env')
>>> print dotenv
{"FOO": "bar", "Bar": "baz"}
>>> dotenv['FOO']
"bar"
>>> dotenv['FOO'] = "baz"
>>> dotenv['FOO']
"baz"
>>> del dotenv['FOO']
>>> print dotenv
{"Bar": "baz"}

Every action is persisted.

Use with Django

# add this to manage.py above `execute_from_command_line(sys.argv)`

from dotenv import Dotenv
dotenv = Dotenv(os.path.join(os.path.dirname(__file__), '.env'))
os.environ.update(dotenv)