Skip to content

fastapi-backend

Repository: github.com/datarobot-community/af-component-fastapi-backend

Adds a FastAPI server to your recipe, deployed as a DataRobot Custom Application. This is the standard API layer for App Framework templates: it pairs with the react component for full-stack applications or stands alone for pure API or server-side-rendered use cases.

The component is repeatable: apply it multiple times with different fastapi_app names to include multiple independent FastAPI backends in a single recipe.

Prerequisites

  • Python 3.11+
  • uv installed
  • dr installed
  • A DataRobot account with permissions to create Custom Applications
  • The base component already applied

Apply

dr component add https://github.com/datarobot-community/af-component-fastapi-backend .

Or with copier directly:

uvx copier copy datarobot-community/af-component-fastapi-backend .

The wizard asks for a fastapi_app name. Use a short, lowercase identifier (e.g., api or web). This name namespaces all generated files and the answers file.

Component dependencies

Component Required
base Yes

Local development

Start the server:

dr run dev

Or directly with uvicorn:

uv run uvicorn FASTAPI_APP.app:app --reload --port 8080

The server is available at http://localhost:8080. FastAPI autodocs are at /docs and /redoc.

Key paths:

Path Purpose
FASTAPI_APP/app/__init__.py FastAPI application and routes.
FASTAPI_APP/templates/index.html Jinja template served by the catch-all route.
FASTAPI_APP/app/static/ Static assets served at /static/.
infra/infra/FASTAPI_APP.py Pulumi Custom Application resources.

Update

dr component update .datarobot/answers/fastapi-FASTAPI_APP.yml

Or with copier directly:

uvx copier update -a .datarobot/answers/fastapi-FASTAPI_APP.yml -A

Adding multiple backends

Because this component is repeatable, run the apply command again with a different fastapi_app name:

uvx copier copy datarobot-community/af-component-fastapi-backend .
# Enter a different `fastapi_app` name when prompted.

Troubleshooting

uvx copier copy fails with a merge conflict

Ensure af-component-base is applied first. This component expects base scaffolding to be present before it runs.

Application fails to start on DataRobot

Check Custom Application logs in the DataRobot UI. The most common cause is a missing environment variable — confirm all required runtime parameters are set in the deployment configuration.

uv run reports a missing package

Run uv sync to install dependencies declared in pyproject.toml.

Port conflict during local development

Change the --port flag in the uvicorn command, or stop any other process already bound to port 8080.