Prompt
How do I deploy a Python app on cloud hosting?
Latest observation
Oct 7, 2026
OpenAI APIWeb search: off
Deploying a Python app on cloud hosting usually looks like this:
1) Prepare your app
Make sure your app can run in production.
- Use a production web server:
- Flask/Django/FastAPI apps often run behind Gunicorn or Uvicorn
- Add a dependency file:
requirements.txtorpyproject.toml
- Define a startup command, for example:
- Flask:
gunicorn app:app - FastAPI:
uvicorn main:app --host 0.0.0.0 --port 8000 - Django:
gunicorn myproject.wsgi:application
- Flask:
- Move config to environment variables:
- secret keys, database URLs, API keys, debug flags
2) Choose a hosting option
Common cloud hosting choices:
- Platform-as-a-Service (easiest):
- Render
- Railway
- Fly.io
- Heroku-like services
- Infrastructure-as-a-Service:
- AWS EC2
- Google Compute Engine
- Azure Virtual Machines
- Container hosting:
- Docker on Cloud Run, ECS, Kubernetes, etc.
If you want the simplest path, use a PaaS like Render or Railway.
3) Put your code in Git
Most cloud platforms deploy from GitHub/GitLab.
- Commit your app to a repo
- Ensure
.gitignoreexcludes local files like:.env__pycache__/- virtual environments
4) Add a production startup file
Many platforms need to know how to start your app.
Example for FastAPI:
gunicorn -k uvicorn.workers.UvicornWorker main:app
Example for Flask:
gunicorn app:app
Example for Django:
gunicorn myproject.wsgi:application
5) Configure environment variables
Set these in your cloud host dashboard:
SECRET_KEYDATABASE_URLDEBUG=FalseALLOWED_HOSTS
Do not hardcode secrets in code.
6) Set up a database if needed
If your app uses a database:
- Create a managed database from your provider
- Update your app to use the cloud database URL
- Run migrations if using Django or Alembic
7) Deploy
Typical deployment flow:
- Connect your Git repo to the hosting service
- Select the branch to deploy
- Set build/start commands
- Add environment variables
- Deploy
8) Test after deployment
Check:
- App loads in browser
- Logs show no errors
- Static files are served correctly
- Database connection works
- Background jobs/tasks run if needed
Example deployment setups
Flask on Render
- Build command:
pip install -r requirements.txt - Start command:
gunicorn app:app
FastAPI on Railway
- Build:
pip install -r requirements.txt - Start:
uvicorn main:app --host 0.0.0.0 --port $PORT
Django on Cloud Run
- Package with Docker
- Use Gunicorn as the entrypoint
- Set environment variables in Cloud Run
9) Optional: use Docker
Docker makes deployment more portable.
Example Dockerfile:
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["gunicorn", "app:app"]
If you want, I can give you a step-by-step deployment guide for a specific framework like Flask, Django, or FastAPI, and for a specific host like Render, AWS, or Google Cloud.