---
title: Build a Python FastAPI app
description: Create a FastAPI app that uses the governed Python SDK and preview readiness path.
section: Guides
sidebarLabel: Build a Python FastAPI app
order: 60
updated: "2026-06-11"
status: beta
llms: true
keywords:
  - Python
  - FastAPI
  - readiness
  - RelpinDb
---

Relpin supports Python FastAPI apps during open beta. The Python SDK gives the app a governed database path and a preview readiness signal.

## Create from a Python starter

Start with a Python or FastAPI template in Studio. The template includes the SDK wiring Relpin expects for preview and publish.

## Add readiness middleware

FastAPI preview uses a readiness endpoint owned by the SDK middleware.

```python
from fastapi import FastAPI
from relpin_sdk import RelpinReadinessMiddleware

app = FastAPI()
app.add_middleware(RelpinReadinessMiddleware)
```

The middleware responds on `/__relpin/ready`. The preview sidecar uses that signal to decide when the app can receive traffic.

## Query governed data

Use `RelpinDb` for data access. The app sends queries over the governed transport; it does not read a raw database connection string.

```python
from relpin_sdk import RelpinDb

async def list_orders() -> dict[str, object]:
    with RelpinDb() as db:
        rows = await db.fetch_all_async("select id, status from orders limit 20")
    return {"orders": rows}
```

## Prefer helpers for simple tables

For simple table reads, use the table helpers documented in [Python table helpers](/docs/sdk/python/table-helpers). Drop down to SQL when you need joins or aggregates.
