Skip to content

Supabase Integration

  1. Navigate to Integrations in your team sidebar
Team Integrations page with Connect buttons for Logfire, Neon, Redis Cloud, and Supabase. Team Integrations page with Connect buttons for Logfire, Neon, Redis Cloud, and Supabase.
  1. Click Connect on the Supabase integration
  2. You’ll be redirected to Supabase to authorize FastAPI Cloud
  3. 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 Integrations tab in the app details and click Connect Integration
App Integrations page with no connected integrations and the Connect Integration button. App Integrations page with no connected integrations and the Connect Integration button.
  1. Click Select on the Supabase integration
Add Integration dialog with the Supabase account connected and its Select button available.
Add Integration dialog with the Supabase account connected and its Select button available.
  1. Choose a project
Supabase project selection with the region shown for each project.
Supabase project selection with the region shown for each project.
  1. Enter your database password and click Connect Database
Supabase database password form with a password reset link and the Connect Database button.
Supabase database password form with a password reset link and the Connect Database button.
  1. Review the selected project and environment variable, then connect it. You can optionally trigger an immediate redeployment
Supabase confirmation dialog with the selected project, environment variable, and Connect and Redeploy button.
Supabase confirmation dialog with the selected project, environment variable, and Connect and Redeploy button.

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