Problem Statement
What are safe ways to manage secrets for a Python app?
Explanation
Never commit secrets to source control. Load them from environment variables, secret managers, or an encrypted vault. Limit scope using least privilege and rotate keys regularly.
In code, read once at startup, validate presence, and avoid printing values. In logs and errors, mask tokens to prevent leaks.
Code Solution
SolutionRead Only
import os API_KEY = os.environ['PAYMENT_KEY'] # pulled from a secret store in production
