read .env(-ish) configuration file for python web applications
- clean code base
- simple api
- adheres to recent .env regulation
pip install dotenv-python
Put .env file at root directory.
Learn about .env file from https://github.com/bkeepers/dotenv
- Initialize
from dotenv import DotEnv
# if .env file is at the same directory
dotenv = DotEnv()
# or else
dotenv = DotEnv('/path/to/your/.env')
- Get value by key
# if not exist or value is 'null', None return
value = dotenv.get('KEY')
# or you can specify a default value
value = dotenv.get('KEY', 'default')
- Check if key exists
# True if exists and False if not
exist = dotenv.has('KEY')
- Get all env data as Dict
data = dotenv.all()
- Print all data to screen
dotenv.dump()