Python applications: Django, Flask and FastAPI.

How Django, Flask and FastAPI projects are detected and started, which entry point we look for, static files, migrations and running Celery.

2 MIN READ

A repository with requirements.txt, pyproject.toml, Pipfile or manage.py is a Python project. We recognise Django, Flask and FastAPI and start them with a production server — you don't add one yourself.

How it is built and run

  • Python 3.11.
  • Dependencies — pip install -r requirements.txt, or pip install . for a pyproject.toml.
  • Server — Django and Flask run on gunicorn, FastAPI on uvicorn. We add the server to the installation ourselves.

Django

  • Recognised by manage.py or django in the requirements.
  • The entry point is read from DJANGO_SETTINGS_MODULE in manage.py — <project>.wsgi:application.
  • Static files — python manage.py collectstatic runs during the build. Serve them from the application with WhiteNoise (add it to your middleware) or from object storage.
  • Migrations — the recommended release command is python manage.py migrate --noinput. It runs on every deploy before the new version receives visitors; if it fails, the current version keeps running.
  • Add your domain and the rivervo.app address to ALLOWED_HOSTS (for example from a variable), and set CSRF_TRUSTED_ORIGINS for HTTPS forms.

Flask and FastAPI

We look for the file that creates the application — app.py, main.py, wsgi.py, application.py or server.py — and the variable it is stored in:

# app.py
from flask import Flask
app = Flask(__name__)      # → started as app:app
# main.py
from fastapi import FastAPI
app = FastAPI()            # → started as main:app

If your application is created somewhere else (an application factory, a package), set Settings → Build settings → Start command, for example:

gunicorn "myproject:create_app()" --bind 0.0.0.0:$PORT
uvicorn myproject.api:app --host 0.0.0.0 --port $PORT

Databases

Add PostgreSQL or MySQL to the project and read DATABASE_URL — with dj-database-url for Django, or directly with SQLAlchemy. See Databases.

Celery and other workers

Add Valkey to the project and point Celery at REDIS_URL. Run the worker:

  • on the Processes tab as a background worker — celery -A myproject worker -l info;
  • or as a separate background worker service with its own resources;
  • Celery beat as one more background worker — celery -A myproject beat -l info — or a periodic command as a scheduled command or a scheduled job.

See Services of a project.

Files that outlive a deploy

Each deploy starts from a fresh copy of your repository. Files your application writes to /data are kept between deploys and backed up daily; anything written elsewhere is gone after the next deploy. For user uploads, use object storage (for Django, django-storages with the S3_* variables).

Other Python projects

A Python project that uses none of these frameworks needs a Dockerfile of its own in the repository; we then build with it as it is.

Still stuck?

Chat with a real engineer — median response under 3 minutes, any time of day.

Contact support