Skip to content

Supabase Integration

  1. Navigate to Integrations in your team settings
  2. Click Connect on the Supabase integration
  3. You’ll be redirected to Supabase to authorize FastAPI Cloud
  4. Grant the requested permissions and you’ll be redirected back

FastAPI Cloud requests read access to your projects, databases, and organizations.

After connecting your Supabase account, you can link a project’s database to any app in your team:

  1. Go to your app’s Storage tab in the app details
  2. Select the Supabase integration
  3. Choose a project
  4. Enter your database password
  5. Optionally trigger an immediate redeployment

FastAPI Cloud will automatically create a DATABASE_URL environment variable with the full PostgreSQL connection string and store the credential as an encrypted secret.

The default environment variable name is DATABASE_URL. You can customize this when connecting (e.g., SUPABASE_DATABASE_URL if you already have a DATABASE_URL in use).

Here’s an example of how to use your Supabase database connection automatically available via the DATABASE_URL environment variable, in a FastAPI app with SQLModel:

app/main.py
import os
from fastapi import FastAPI
from sqlmodel import Field, Session, SQLModel, create_engine, select
class Hero(SQLModel, table=True):
id: int | None = Field(default=None, primary_key=True)
name: str = Field(index=True)
secret_name: str
age: int | None = Field(default=None, index=True)
# The database URL is automatically injected as an environment variable
engine = create_engine(os.getenv("DATABASE_URL"))
def create_db_and_tables():
SQLModel.metadata.create_all(engine)
app = FastAPI()
@app.on_event("startup")
def on_startup():
create_db_and_tables()
@app.post("/heroes/")
def create_hero(hero: Hero):
with Session(engine) as session:
session.add(hero)
session.commit()
session.refresh(hero)
return hero
@app.get("/heroes/")
def read_heroes():
with Session(engine) as session:
heroes = session.exec(select(Hero)).all()
return heroes