Python·100 questions

How to read environment variables in Python?

Answer
import os.
os.environ['KEY'] (will crash if missing).
os.getenv('KEY', default) is safer.
Convert types explicitly (int/bool).
For .env, use python-dotenv (in dev).
Was this answer helpful?

More questions in this topic

Related questions from other topics