getenv

os.getenv returns None or a default if the key is missing.

import os
api_key = os.getenv('API_KEY', '')