Configuration and deployment
Configure the server, database, secrets, proxy boundary, and production process.
Work through each step in order. The examples use the generated LenAPI project structure and are designed to be adapted to your app.
Set deployment configuration
The generated settings module controls host, port, database type and URL, async mode, docs paths, and security settings. Defaults target local development.
# settings.py
HOST = "" # blank uses 127.0.0.1
PORT = 8009
DATABASE_TYPE = "postgresql"
DATABASE_URL = "postgresql+psycopg://user:password@db/app"
ACTIVATE_ASYNC = TrueDistinguish omitted values from None
LENAPI() inherits optional configuration from settings.py when an argument is omitted. Passing None explicitly can disable options such as Swagger docs or request body limits. Use the public UNSET sentinel in your own functions when omission and None need different meanings.
from lenapi import LENAPI, UNSET
# Explicitly disable docs and body limits, even if settings.py enables them.
app = LENAPI(docs_url=None, max_request_body_size=None)
def update_value(value=UNSET):
if value is UNSET:
return "leave the stored value unchanged"
return value # None is an explicit value and may clear a nullable field.For Pydantic PATCH bodies, use model_dump(exclude_unset=True); Pydantic already tracks the fields the client sent.
Run a production ASGI server
Run Uvicorn against the application object. Use a process manager or container platform to supervise production workers, and configure trusted proxy behavior at the edge.
uvicorn main:app --host 0.0.0.0 --port 8009Build and run with Docker
Use a slim Python image, install Git during the build if requirements install LenAPI from a Git URL, install dependencies, and run Uvicorn on the container interface. Keep local secrets and database files out of the build context. Run the schema migration before the first request when database-backed security storage is enabled. Persist SQLite storage with a volume, or use a managed SQL database for production.
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN apt-get update && apt-get install -y --no-install-recommends git && pip install --no-cache-dir -r requirements.txt && apt-get purge -y --auto-remove git && rm -rf /var/lib/apt/lists/*
COPY . .
EXPOSE 8009
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8009"]
# .dockerignore should include .env, .venv/, __pycache__/, *.db, and .git/.
docker build -t my-lenapi-app .
docker volume create lenapi-data
docker run --rm --env-file .env --mount source=lenapi-data,target=/data -e DATABASE_URL=sqlite:////data/lenapi.db my-lenapi-app python lenora.py migration
docker run --rm -p 8009:8009 --env-file .env --mount source=lenapi-data,target=/data -e DATABASE_URL=sqlite:////data/lenapi.db my-lenapi-appDeploy from Coolify
Create an application from the Git repository, select the Dockerfile build pack, and point Coolify at the directory containing the app Dockerfile. Set the container port to match EXPOSE, add secrets through Coolify environment variables, attach persistent storage if using SQLite, and configure the HTTPS domain. Run migrations once as a deployment or release step before serving traffic.
# Coolify application settings
Build pack: Dockerfile
Dockerfile: ./Dockerfile
Port: 8009
Start command: use the Dockerfile CMD
# Add in Coolify environment settings:
DATABASE_TYPE=postgresql
DATABASE_URL=postgresql+psycopg://user:password@db/app
SECRET_KEY=<generated-secret>
# Deployment migration step:
python lenora.py migration
python lenora.py migrateDo not commit production .env files or database files. If Coolify builds from a monorepo, set the build context and Dockerfile path to the generated LenAPI project directory.
Protect secrets and persistent data
Keep generated signing keys, OAuth client secrets, and API keys outside source control. Use HTTPS, persistent database storage, shared throttle/session storage for multiple workers, and backups.
The built-in WebSocket room manager and memory cache are process-local. Use a shared backend or external service when scaling across processes or hosts.
Use the docs and health endpoints deliberately
Swagger and OpenAPI are enabled by default and can be renamed or protected. Decide whether your production API documentation should be public or gated by the database-backed admin session feature.
app = LENAPI(
title="My API",
version="1.0.0",
docs_url="/docs/",
openapi_url="/openapi.json",
)