How do you handle configuration in a Python tool?
IntermediateConceptBest practices & rapid-fire commands
Answer
Layer it, with clear precedence: built-in defaults, then a config file (YAML/TOML), then environment variables, then CLI flags (highest). Validate the merged result at startup with pydantic or explicit checks and fail with a clear message. Use tomllib (standard library since 3.11) to read TOML. Keep secrets out of config files; reference a secret name and resolve it at runtime. Twelve-factor services usually need only env vars (pydantic-settings reads them into a typed model).
More on Best practices & rapid-fire commands
What does a production-quality automation script always include?IntermediateWhat are the most common security mistakes in Python ops code?AdvancedBash or Python for this task: how do you decide?BeginnerRapid fire: set up a project environment from scratch.BeginnerRapid fire: one-liners useful during an incident.IntermediateRapid fire: pytest commands.Beginner