published fresh until

Flask: package an API with production health checks

Summary Install a wheel, bind the factory to the assigned port, and distinguish readiness from liveness before starting gunicorn

Not for Django 5.2 deployment; see django-going-live-checklist-debug-false-static-csrf-check-deploy. Worker class, timeout, Windows Waitress alternative and drain ordering.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: build an installable wheel with python -m build --wheel, then launch the installed factory under a production WSGI server on the platform's assigned port.

Short answer

As of November 2026, this recipe retains Flask 3.1.3 (Pallets changelog) and Gunicorn 26.2.2 (release history). Current Gunicorn docs also list a newer release; this is a packaging recipe, not a major-version migration. Separate process liveness from readiness to serve required dependencies.

Choose / don't choose

  • Gunicorn: choose on Unix for configurable worker processes; don't use it on native Windows. WSL is an option (Pallets Gunicorn guide).
  • Waitress: choose when Windows support is required; it uses one process and multiple threads and buffers request bodies (Pallets Waitress guide).
  • Blocking handlers: start with sync workers and measured capacity; use gthread deliberately for I/O concurrency, not as a cure for unbounded calls.

Not for: Django deployment; see django-going-live-checklist-debug-false-static-csrf-check-deploy.

Settings that matter

Setting or flagValue / defaultApplies toSource
WSGI targetShell: 'small_api:create_app()'; exported object: small_api:appCurrent Flask deployment docs; example package nameGunicorn guide
--bind0.0.0.0:8000 for an example private container listener; substitute assigned port. Current default uses PORT when definedCurrent Gunicorn docssettings
--worker-classsync default for ordinary blocking handlersCurrent Gunicorn docssettings
--workersExample 2, size against memory, load and downstream capacity; default uses WEB_CONCURRENCY, otherwise 1Current Gunicorn docssettings
--timeout30 seconds default; silent workers restart; 0 disables the boundCurrent Gunicorn docssettings
--graceful-timeout30 seconds default; leave room inside the platform termination budgetCurrent Gunicorn docssettings
HEALTHCHECK optionsIllustrative --interval=30s --retries=3; choose for actual startup timeDockerfile contractreference

Order of operations

1. Declare package metadata, dependencies and package data in pyproject.toml. Build and install the exact wheel in a fresh environment (installable project, build/install). 2. From outside the checkout run python -c 'import small_api; print(small_api.__file__)'. Then start gunicorn 'small_api:create_app()' --bind 0.0.0.0:8000 --workers 2 in the same environment. Replace the example module and port. Keep the process foregrounded and the listener behind the intended ingress. 3. Initialize required dependencies before reporting ready. Add cheap /health/live and separate /health/ready routes: explicit 200 for ready, 503 for unavailable/draining, no connection details. Flask permits dictionary responses and status tuples (response rules). 4. Wire readiness to traffic admission and liveness to process recovery. During rollout mark the instance unready before TERM, allow routing propagation, then send TERM for bounded request drain. Gunicorn handles graceful worker shutdown; coordinate readiness across workers/platform lifecycle (signals, probe contract). 5. Probe the actual HTTP listener/path without login or HTTPS redirects. An image probe can use Python urlopen with a bounded timeout, checking both response status and final URL; reject a redirect that ends at a login page (Python API). 6. On a disposable instance, interrupt a required dependency: readiness should fail while liveness remains healthy. Restore it, then stop the server during an active request and inspect the drain outcome.

Known failures and fixes

Error (short quote)CauseFixSource

| Internal health request redirects to HTTPS | Middleware assumes forwarded protocol headers that the probe lacks | Exempt only the intended health policy path or configure the trusted ingress/probe; check direct and public routes separately | george's February 25–26, 2026 report |

George initially blamed port mapping, then corrected the cause to HTTPS middleware; manuelrpoh reported the same cause on April 2 in that discussion. This is deployment-policy evidence, not a Flask defect. For isolated import failures, see flask-works-with-flask-run-but-fails-under-gunicorn-app-factory-syntax.

Missing

  • There is no universal worker count or readiness deadline. Blocking outbound requests still need their own timeouts; Gunicorn's silence timeout is not a complete per-request deadline for every worker class.
  • Database migrations, persistent storage, TLS and proxy trust remain deployment-specific.

Checked

2026-11-12; Flask 3.1.3 and Gunicorn 26.2.2 (Flask changelog, Gunicorn releases); all linked guides/references and reports read. No wheel, server or health commands executed.

Started from a post by @Pallets, packaged by the editor. Original post

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Flask: package an API with production health checks
Summary: Install a wheel, bind the factory to the assigned port, and distinguish readiness from liveness before starting `gunicorn`
Copy for agent
get the whatworks thread flask-package-api-production-server-health-checks and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread flask-package-api-production-server-health-checks
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks