Тип сервиса
Сервис Python (FastAPI)
Среда выполнения Python для приложений и API на FastAPI, которые обслуживаются Gunicorn и Uvicorn.
Этот сервис запускает ваш код: его образ собирается из Git-репозитория, а каждая сборка развёртывается в окружение.
В StackMaster
Как Python (FastAPI) работает в StackMaster
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_APPnames the WSGI callable asmodule:callable. The image default ismyapp.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.
| Link | Variables |
|---|---|
| Database (MariaDB, MySQL or PostgreSQL) | DB_HOST, DB_PORT, DB_NAME (also DB_DATABASE), DB_USERNAME, DB_PASSWORD, DB_DRIVER (also DB_CONNECTION) |
SMTP_HOST, SMTP_PORT | |
| Redis or Valkey | REDIS_HOST, REDIS_PORT, REDIS_PASSWORD |
| OpenTelemetry Collector | OTEL_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_HOSTSis a JSON array of the environment's hosts, not a comma-separated string.WODBY_PRIMARY_HOSTandWODBY_PRIMARY_URLare the canonical ones for links generated outside a request.WODBY_APP_SERVICE_NAMEis this service's host name inside the environment. Other services reach the application at that name on port 8080.WODBY_ENV_TYPEtells 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/appand served as it is on disk. - Workspace setup installs dependencies with
workspace-python prepare:uv sync --lockedwhenuv.lockexists, otherwisepip install -r requirements.txtinto a virtual environment. One of the two must exist. Run it again after changing dependencies. - The virtual environment is
.wodby-workspace/venvin the checkout..wodby-workspace/and__pycache__/are kept out of Git status without touching.gitignore. Use.wodby-workspace/venv/bin/pythonfor commands that need the application's packages. - The application is started with
python -m gunicorn --bind "$HOST:$PORT" --reload --reload-engine poll "$GUNICORN_APP", withHOSTandPORTdefaulting to0.0.0.0and8080. The generated Gunicorn configuration and theGUNICORN_*tuning variables are not used here. WORKSPACE_PYTHON_COMMANDon 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:8080from the container shows whether the application answers on the expected port.printenv | grep -E '^(DB|SMTP|REDIS)_' | cut -d= -f1lists the link variables that are present.
FastAPI on Wodby
What this service adds to the Python service it is based on.
Variables the service sets
| Variable | Meaning |
|---|---|
GUNICORN_APP | main:app: the ASGI application is the object app in main.py at the root of the repository. Change the variable on the service when it lives elsewhere. |
GUNICORN_WORKER_CLASS | uvicorn_worker.UvicornWorker. Gunicorn stays the process manager and runs the application through Uvicorn workers. |
WORKSPACE_PYTHON_COMMAND | The start command of a development workspace, see below. |
The worker class comes from the uvicorn-worker package. The image does not include it, nor Gunicorn: both must be among the application's dependencies. Without uvicorn-worker Gunicorn fails to start.
Do not add a uvicorn start command to the Dockerfile and do not change the port: the container still starts Gunicorn on port 8080, as described for the Python service. The number of workers is GUNICORN_WORKERS.
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. FastAPI has no settings convention of its own: the names to read are exactly the ones listed for the Python service.
In a development workspace
The application is started with Uvicorn instead of Gunicorn:
python -m uvicorn "$GUNICORN_APP" --host "$HOST" --port "$PORT" --reloaduvicorn is installed by workspace preparation as a dependency of uvicorn-worker. Its reloader picks up a saved Python file without a restart; WATCHFILES_FORCE_POLLING is set, so the watchfiles reloader polls when that package is installed. A change to dependencies needs workspace preparation again.
Check the result
curl -s localhost:8080/openapi.jsonfrom the container returns the generated schema when the application is up, unless the project disabled it.
Обзор
Технический профиль Python (FastAPI)
Версии
Основан на
Репозиторий исходного кода
Публичный Helm-чарт
Стеки
Стеки, в которые входит Python (FastAPI)
CI/CD
Сборка Python (FastAPI) из Git-репозитория
FastAPI boilerplate
Используйте его как есть или клонируйте в свой Git-аккаунт.
wodby/fastapi-boilerplateCI-провайдеры
StackMaster CI встроен в платформу: пайплайн описывается в файле .wodby/pipeline.yml в репозитории. Для подключённого репозитория те же шаги может выполнять внешний CI-провайдер с помощью StackMaster CLI.
Реестры контейнеров
Собранные образы по умолчанию попадают в StackMaster Registry или во внешний реестр, подключённый как интеграция.
Переменные окружения из интеграций
Интеграция с переменными один раз сохраняет учётные данные стороннего сервиса. Подключите её к Python (FastAPI), и StackMaster передаст их в контейнер как переменные окружения во время работы, а не при сборке образа.
Конфигурация
Конфигурация сервиса Python (FastAPI)
Технические домены
Связи сервиса
Каждая связь — это подключение Python (FastAPI) к другому сервису. На какой сервис указывает связь, задаёт стек. На карточках перечислены публичные сервисы, которые подходят для каждой связи.
db
Сервисы, которые подходят для этой связи
sendmail
Сервисы, которые подходят для этой связи
redis
Сервисы, которые подходят для этой связи
otel
Сервисы, которые подходят для этой связи