Letting the KeyError go is usually fine, but if you want to log it or can recover somehow then:
try: API_KEY = os.environ["API_KEY"] except KeyError: logger.exception("...") ...
Letting the KeyError go is usually fine, but if you want to log it or can recover somehow then: