Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

1. Create and deploy a Python and Flask hello app

You will see a hello response at / and ok at /health before adding any services.

1. Download and run locally

Download the hello ZIP into a working directory, then open a terminal in that directory:

unzip python-hello.zip
cd python-hello
python3.13 -m venv .venv
. .venv/bin/activate
python -m pip install -r requirements.txt
gunicorn --bind 0.0.0.0:3000 app:app

Keep it running. In another terminal, curl -fsS http://localhost:3000/health should print ok. Open http://localhost:3000/ and confirm the hello message. Stop the server with Ctrl+C.

The app source is small enough to inspect in full:

.python-version

3.13

requirements.txt

blinker==1.9.0
click==8.5.0
Flask==3.1.3
gunicorn==23.0.0
itsdangerous==2.2.0
Jinja2==3.1.6
MarkupSafe==3.0.4
packaging==26.3
Werkzeug==3.1.9

Procfile

web: gunicorn --bind 0.0.0.0:$PORT app:app

app.py

import os
from flask import Flask
app = Flask(__name__)
@app.get('/')
def index():
    return 'Hello from Python on d2o!\n'
@app.get('/health')
def health():
    return 'ok\n'
if __name__ == '__main__':
    app.run(host='0.0.0.0', port=int(os.getenv('PORT', '3000')))

Keep the supplied lockfiles in Git. The buildpack uses these manifests and its runtime version declaration to reproduce the app’s dependencies.

2. Create the Environment

Dashboard: open Project Examples → create Environment python, type Development, branch main, release source Build, Automatic deployment on.

CLI:

paas envs create python -o "$TUTORIAL_ORG" -p examples --type development --branch main --release-source build

3. Create the web app

Dashboard: inside python choose Add Resource → Web Application. Name it notes-web, choose Framework Python, Repository The environment’s shared repository, Directory blank (repository root), and Process type web. Use Port 3000, Health Check Path /health, and one replica. Click Create Resource.

CLI:

paas apps create notes-web --framework python --shared-source --start-command web --port 3000 --health-check-path /health -o "$TUTORIAL_ORG" -p examples -e python

4. Commit and push

Initialize a repository in the unpacked hello directory:

git init -b main
git add .
git commit -m "Add hello application"

Dashboard path: open the Environment’s Git remote panel, copy its shared-repository remote command into this directory, then run its push command. This is the Environment remote, not a per-app remote. The dashboard supplies the correct host and authentication URL.

CLI path: omit -a when setting the shared remote:

paas git remote -o "$TUTORIAL_ORG" -p examples -e python
git push d2o main
paas watch -a notes-web -o "$TUTORIAL_ORG" -p examples -e python

5. Verify the deployed app

Dashboard: open notes-web → Deployments, wait for the successful build and running instance, then open its public URL. Append /health; it should display ok. CLI: paas ps and paas logs with -o "$TUTORIAL_ORG" -p examples -e python and -a notes-web show the running process. Use the public URL displayed in the dashboard, or read the url field from paas apps info notes-web --json with the same Organization, Project, and Environment flags.

APP_URL=https://your-app-host
curl -fsS "$APP_URL/health"
curl -fsS "$APP_URL/"

Set APP_URL to your actual URL, with no trailing slash. If the build fails, see troubleshooting before continuing.

Next: Persist notes in PostgreSQL.