App service
Services/Python (Flask)

Python (Flask) service

Python runtime service for lightweight Flask web apps, APIs, and custom application workloads.

This service runs your code: its image is built from a Git repository, and each build is deployed to an app environment.

On Wodby

How Python (Flask) runs on Wodby

What Wodby sets up for an application that runs on this service. Check it before adding a server configuration or connection settings to the code.

How the application is started

The container runs Gunicorn with a configuration file the image writes on every start:

gunicorn -c /usr/local/etc/gunicorn/config.py --pythonpath "$GUNICORN_PYTHONPATH" "$GUNICORN_APP"
  • GUNICORN_APP names the WSGI callable as module:callable. The image default is myapp.wsgi:application; set the variable on the service, or in the Dockerfile, when the application lives elsewhere.
  • Gunicorn listens on 0.0.0.0:8080. The port is fixed in the generated configuration and is the port of the service's HTTP endpoint.
  • The image does not include Gunicorn. It must be one of the application's dependencies.
  • Access and error logs go to the container's output.

Do not add a Gunicorn configuration file to the repository to change workers or timeouts: the container does not load it. Set these variables on the service instead: GUNICORN_WORKERS, GUNICORN_WORKER_CLASS, GUNICORN_WORKER_CONNECTIONS, GUNICORN_TIMEOUT, GUNICORN_KEEPALIVE, GUNICORN_BACKLOG, GUNICORN_LOGLEVEL, GUNICORN_PROC_NAME, GUNICORN_PYTHONPATH. A change applies with the next deployment of the service.

Linked services

Links to other services reach the application as environment variables. Nothing in the image reads them: the application reads them itself. Do not hardcode hosts or credentials.

LinkVariables
Database (MariaDB, MySQL or PostgreSQL)DB_HOST, DB_PORT, DB_NAME (also DB_DATABASE), DB_USERNAME, DB_PASSWORD, DB_DRIVER (also DB_CONNECTION)
MailSMTP_HOST, SMTP_PORT
Redis or ValkeyREDIS_HOST, REDIS_PORT, REDIS_PASSWORD
OpenTelemetry CollectorOTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_PROTOCOL (http/protobuf), OTEL_EXPORTER_OTLP_HEADERS (the Collector's ingest token)

All links are optional. A variable is present only while its link exists and the linked service is enabled. The mail link carries no credentials. The OpenTelemetry variables are the standard SDK settings: an application or agent that uses an OpenTelemetry SDK exports to the Collector without further configuration; set OTEL_SERVICE_NAME to name the application in traces.

Environment

  • WODBY_HOSTS is a JSON array of the environment's hosts, not a comma-separated string. WODBY_PRIMARY_HOST and WODBY_PRIMARY_URL are the canonical ones for links generated outside a request.
  • WODBY_APP_SERVICE_NAME is this service's host name inside the environment. Other services reach the application at that name on port 8080.
  • WODBY_ENV_TYPE tells a development environment from a production-like one.

Build

The code is copied to /usr/src/app, the working directory. The service's own Dockerfile then runs pip install -r requirements.txt when that file exists, and nothing else. A pipeline that passes a Dockerfile from the repository (wodby ci build python -f Dockerfile) uses that file instead, and the repository's Dockerfile then owns dependency installation. uv is available in the image.

The service declares no volume of its own: files written inside the container are lost when it is replaced.

In a development workspace

  • The checkout is mounted at /usr/src/app and served as it is on disk.
  • Workspace setup installs dependencies with workspace-python prepare: uv sync --locked when uv.lock exists, otherwise pip install -r requirements.txt into a virtual environment. One of the two must exist. Run it again after changing dependencies.
  • The virtual environment is .wodby-workspace/venv in the checkout. .wodby-workspace/ and __pycache__/ are kept out of Git status without touching .gitignore. Use .wodby-workspace/venv/bin/python for commands that need the application's packages.
  • The application is started with python -m gunicorn --bind "$HOST:$PORT" --reload --reload-engine poll "$GUNICORN_APP", with HOST and PORT defaulting to 0.0.0.0 and 8080. The generated Gunicorn configuration and the GUNICORN_* tuning variables are not used here.
  • WORKSPACE_PYTHON_COMMAND on the service replaces that start command. A custom command must do its own reloading.
  • A change to variables or linked services still needs a deployment of the environment.

Check the result

  • curl -s -o /dev/null -w '%{http_code}' localhost:8080 from the container shows whether the application answers on the expected port.
  • printenv | grep -E '^(DB|SMTP|REDIS)_' | cut -d= -f1 lists the link variables that are present.

Flask on Wodby

What this service adds to the Python service it is based on.

Variables the service sets

VariableMeaning
GUNICORN_APPapp:app: the WSGI application is the object app in the module or package app at the root of the repository. Change the variable on the service when it lives elsewhere, for example to call an application factory.
FLASK_DEBUGSet to true in environments of type dev only. Absent in every other type.

The application is served by Gunicorn on port 8080, as described for the Python service, not by flask run. Do not add a flask run start command or an app.run() call for deployment. Flask and Gunicorn must both be among the application's dependencies: the image includes neither.

The service sets no other FLASK_* variable and no secret key. An application that uses sessions provides its own SECRET_KEY, as a secret variable on the service.

Linked services

The service adds no link variables. The database, mail and Redis or Valkey variables of the Python service apply unchanged, and the application reads them itself: Flask does not read DB_*, SMTP_* or REDIS_*.

In a development workspace

Gunicorn runs with its polling reloader against GUNICORN_APP, so a saved Python file is picked up without a restart. A change to dependencies needs workspace preparation again.

Overview

Technical profile of Python (Flask)

The versions are the ones you can select for Python (Flask) in a stack or an app environment. The service itself is published in revisions, and a stack references a specific revision.

Service type

App service

Versions

3.15, 3.14, 3.13, 3.12, 3.11, 3.10

Stacks

Stacks that include Python (Flask)

This public stack includes Python (Flask). You can create an app from a public stack as it is, or add the service to a stack of your own.

CI/CD

Build Python (Flask) from a Git repository

Start from a public boilerplate or connect your own repository. With Wodby CI, a push to the branch that an app environment follows starts a build of Python (Flask), and the pipeline deploys it.

Git providers

You connect a repository through an integration with its Git provider.

CI providers

Wodby CI is built in: the pipeline is the file .wodby/pipeline.yml in the repository. For a repository you connect, an external CI provider can run the same steps with Wodby CLI.

Container registries

Built images go to Wodby Registry by default, or to an external registry that you connect as an integration.

Environment variables from integrations

A variable integration stores the credentials of a third-party service once. Attach it to Python (Flask) and Wodby passes them to the container as environment variables at runtime, not during the image build.

Configuration

Python (Flask) service configuration

The Python (Flask) service declares the following. Where a value can be changed, a stack sets it and each app environment can override it.

Technical domains

Wodby gives each public HTTP port a technical domain with a TLS certificate and renews the certificate. A port that the service marks private gets no domain. You can add custom domains.

Service links

Each link is a connection from Python (Flask) to another service. A stack sets which service a link points to. The cards list the public services that can satisfy each link.