Skip to main content

Python Basic Webserver with Database

Python Basic Webserver with Database logo
Python Basic Webserver with Databasev1.0.0

Flask server that connects to PostgreSQL and reads from a tasks table

A minimal Flask web server that connects to a PostgreSQL database and reads from a tasks table. Demonstrates the full producer/consumer flow — UIS deploys PostgreSQL, dev-template configure creates the database and wires the connection into .env, and the app reads from it. Includes Docker containerization, Kubernetes deployment manifests, and GitHub Actions CI/CD workflow. Consumer-side companion to the postgresql-demo UIS stack template.

Tools: dev-python
Install:dev-template python-basic-webserver-database
Maintainers: terchristerchris
GETTING STARTED

Prerequisites

Files

ENVIRONMENT

What gets set up

When you install this template, the following are configured for you:

In your devcontainer
In your Kubernetes cluster
  • Open-source relational database
    • Databasemy_app_db
    • Usermy_app
    • K8s Secretmy-app-db
    • Port-forwardhost.docker.internal:35432
    • Env varDATABASE_URL
    • Namespacedefault
    • Helm chartbitnami/postgresql
Schema applied to the database

Configure

Set up and configure the backend services this template needs. Creates a per-app database, wires credentials into a local .env file, and stores a Kubernetes Secret in your cluster for the deployed pod.

Uses: PostgreSQL

Then run:

dev-template configure

Setup

uv venv
uv pip install -r requirements.txt

Run the Flask app

uv run python app/app.py

Flask debug server starts on port 3000. VS Code auto-forwards the port — click the globe icon in the Ports tab.

ARCHITECTURE

Architecture

These diagrams are auto-generated from the template's metadata. Click any diagram to enlarge.

Local development

Deployment

Template README

The Python Basic Webserver with Database template is a Flask app that connects to PostgreSQL and reads from a tasks table. The purpose of this app is to verify that both the development environment and the database connection are set up and working. See more documentation at http://localhost:3000/docs/templates/basic-web-server-database/python-basic-webserver-database

Configuration and database URL

  • DATABASE_URL must be set (typically via .env after dev-template configure). If it is missing, the process exits with an error — there is no default connection string.
  • Connections use psycopg2 via get_connection() in app/app.py.

Schema and seed data

  • config/init-database.sql defines the default tasks table, indexes, and seed rows. UIS applies this when you run dev-template configure (see the docs page for the full flow).
  • Change the schema in that file, then run dev-template configure again so the database matches.

HTTP API

PathMethodResponse
/GETHTML greeting with template name, time, and links to /tasks and /health
/tasksGETJSON array of tasks rows (id, title, status, created_at), or 500 with {"error": ...} on query failure
/healthGET{"status": "ok", "database": "connected"} when the DB answers SELECT 1; 503 with {"status": "error", "database": ...} if the connection fails

Entry point and dev server

  • File: app/app.py
  • Port: 3000 (constant in code; align with Dockerfile/manifests if you change it)
  • Run: uv run python app/app.py (or activate a venv and run python app/app.py). Flask debug mode is enabled in if __name__ == '__main__'.

Changing the app

  • Add routes and helpers in app/app.py. Reuse get_connection() for DB access.
  • If you rename tables or columns, update config/init-database.sql and re-run dev-template configure, and keep /tasks in sync with your queries.