import os
# Preferred - no KeyError exceptions even if no default value given
os.getenv('KEY', 'default value')
# Alternate - NOTE: KeyError exception If a key is NOT present
os.environ['KEY']
# To avoid KeyError exceptions when using os.environ :
os.environ.get('KEY_THAT_MIGHT_EXIST') # Returns `None` if key doesn't exist
os.environ.get('KEY_THAT_MIGHT_EXIST', default_value) # Returns `default_value` if key doesn't exist
$ pip install python-decouple
from decouple import config
API_USERNAME = config('USER')
API_KEY = config('KEY')
pip3 install python-decouple