What is .env file?

This is a plain text file containing key value entries like that: FOO=bar


Important: because environment variables are almost always meant to be used for storing secrets you have to make sure it is in your .gitignore and will never travel to repo.


Handling usage of .env files in python (and django) is very easy using that library https://github.com/theskumar/python-dotenv


setting dotenv in django is easy: you need to add it to yours wsgi.py and manage.py and eventually celery.py:

import dotenv
os.path.join(os.path.dirname(os.path.dirname(__file__)), '.env')


you can integrate setting new environment variables on remote machines easily into your fabfile see here: https://github.com/theskumar/python-dotenv#setting-config-on-remote-servers

For transporting the .env file to remote machine just use fabric’s put method.

shell snippet

for fast export from file export $(cat .env)