Deployment Best Practices
Reproducible, observable, reversible releases keep Python APIs available while teams ship daily. These rules apply from Dockerfiles through CI/CD to Kubernetes rollouts.
Search across all documentation pages
Reproducible, observable, reversible releases keep Python APIs available while teams ship daily. These rules apply from Dockerfiles through CI/CD to Kubernetes rollouts.
uv sync --frozen in CI and Dockerfile..dockerignore excludes .venv, tests, git. Smaller context and faster builds.:latest in prod. Immutable artifact per release.--reload.terminationGracePeriodSeconds and Gunicorn --graceful-timeout.0.0.0.0 behind LB/ingress. TLS terminates at edge, not ad-hoc in app container.SecretStr and Sentry scrubbers.maxUnavailable: 0 for HA APIs. Surge new pods before draining old./health after deploy in CI/CD. Block promotion on failure.Tested image, Gunicorn/Uvicorn, health endpoints, env-based config, CI test gate, one-click rollback tag.
Lambda for event/spiky work; K8s for steady HTTP, websockets, and uniform multi-service platform.
Load test - start near CPU count for async I/O services; reduce when memory-bound per worker.
Local dev only - never in image; prod uses platform secret injection.
CDN or object storage for scale; collectstatic in build for Django as needed.
Decouple risky code deploy from exposure - flags off until rollout verified.
Same rolling rules; long-running admin exports may need separate worker or timeout tuning.
PR-triggered deploy with seeded data accelerates review before staging promotion.
Run npx tsx scripts/lint-docs.ts in prebuild when shipping doc site with app monorepo.
Shipping breaking DB migration and code change atomically - always expand-contract across releases.
Stack versions: This page was written for Python 3.14.0 (stable 3.14, maintenance 3.13), FastAPI 0.115+, Django 5.2, Flask 3.1, Pydantic 2, PyTorch 2.6+, pandas 2.2+, Polars 1.x, ruff 0.9+, and uv 0.6+.
Reviewed by Chris St. John·Last updated Jul 16, 2026