A production release combines source, Python version, dependencies, native libraries, configuration, secrets, writable storage, database schema, process supervision, logs, and monitoring. Reproducing only the source checkout is not enough.
After this lesson, you can define a build artifact, inject environment-specific configuration, run the application under a supervisor, separate liveness from readiness, coordinate schema changes, and decide rollback from measured signals.
Declare the supported interpreter range in pyproject.toml and build with the exact production series. Native wheels and optional free-threaded builds need separate compatibility checks. Record python --version and the release identifier with deployment evidence.
python --version
python -m pip check
python -m pip list --format=freeze
pip check detects incompatible installed requirements; a lock or resolved artifact remains necessary for reproducible installation.
Build a wheel or container from a reviewed commit, install locked dependencies in a clean environment, run tests against that artifact, and promote the same artifact between environments. Avoid editing source or installing surprise packages on a live server.
Read environment-specific values at startup, validate them into a typed configuration object, and fail before accepting work when a required value is missing. Never print secrets in a complete environment dump.
from dataclasses import dataclass
import os
@dataclass(frozen=True)
class Settings:
database_url: str
environment: str
def load_settings() -> Settings:
database_url = os.environ.get("DATABASE_URL", "")
if not database_url:
raise RuntimeError("DATABASE_URL is required")
return Settings(database_url, os.environ.get("APP_ENV", "production"))
The program validates configuration once instead of scattering os.environ lookups across business code.
Use an operating-system service manager, container orchestrator, or suitable application server to start, stop, restart, and observe long-running processes. A development server is not a production process model.
Liveness shows that the process can respond. Readiness shows that the instance is prepared to receive traffic. Keep checks fast and avoid turning a downstream outage into a storm of expensive probes.
import json
import os
health = {
"status": "ok",
"release": os.environ.get("APP_RELEASE", "unknown"),
}
print(json.dumps(health, separators=(",", ":")))
{"status":"ok","release":"unknown"}
During a rolling release, old and new processes may run together. Add backward-compatible schema first, deploy code that understands both shapes, migrate data, and remove old fields in a later release. Test restoration, not only backup creation.
0 of 2 checked
Try this next
0 of 2 completed
Explore 500+ free tutorials across 20+ languages and frameworks.