# Keeping Secrets Out of Your Code

A secret typed into the code goes wherever the code goes, GitHub included, so an API reads its secrets from environment variables, keeps them in a .env file that .gitignore leaves out, commits a .env.example instead, stops at startup when one is missing, and rotates any secret that was ever pushed.

![Cheat sheet: Keeping Secrets Out of Your Code](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/6a502826fe06462490d0cd2f25e0bf3a.webp)

- Category: FastAPI
- Level: Journeyman
- Tags: env-file, Environment Variable (python), fastapi, gitignore, Secret Rotation, web-development
- Author: Gregor Dzierzon
- Updated: November 23, 2026

Source: https://www.ask-codey.com/cheat-sheets/fastapi-security-secrets-cheat-sheet
