1import os
2
3# Set environment variables
4os.environ['API_USER'] = 'username'
5os.environ['API_PASSWORD'] = 'secret'
6
7# Get environment variables
8USER = os.getenv('API_USER')
9PASSWORD = os.environ.get('API_PASSWORD')
10
11# Getting non-existent keys
12FOO = os.getenv('FOO') # None
13BAR = os.environ.get('BAR') # None
14BAZ = os.environ['BAZ'] # KeyError: key does not exist.
15
1from decouple import config
2
3API_USERNAME = config('USER')
4API_KEY = config('KEY')
5