Earlier quoted context omitted.
This is nitpicking, but this is a good usecase for the := operator: if not (API_KEY := os.getenv("API_KEY")): ... For internal tools I just let os.environ["API_KEY"] raise a KeyError. It's descriptive enough.
I always forget this syntax exists. When was this introduced?
Really nice to combine 1) checking if something exists and 2) act on it