4 min read
Configuration and Environment Variables
An environment variable is a value set outside the program (by the operating system or hosting platform) — the standard place to put secrets like API keys and database passwords, so they're never written directly into source code.
import os
api_key = os.environ.get("API_KEY")
Common mistakes
- Hard-coding a secret directly in a
.pyfile that gets committed to version control — anyone with access to the repository's history can then read it, even after it's later removed.