Skip to content

Neon 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 Neon integration
  2. You’ll be redirected to Neon to authorize FastAPI Cloud
  3. Grant the requested permissions and you’ll be redirected back

FastAPI Cloud requests read access to your projects and organizations.

After connecting your Neon account, you can link a specific 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 Neon integration
Add Integration dialog with the Neon account connected and its Select button available.
Add Integration dialog with the Neon account connected and its Select button available.
  1. If you belong to multiple Neon organizations, select the organization first
Neon organization selection with two available organizations.
Neon organization selection with two available organizations.
  1. Choose your project
Neon project selection with two available projects.
Neon project selection with two available projects.
  1. Choose a branch
Neon branch selection with production and staging branches.
Neon branch selection with production and staging branches.
  1. Choose a database
Neon database selection for the chosen branch.
Neon database selection for the chosen branch.
  1. Review the selected database and environment variable, then connect it. You can optionally trigger an immediate redeployment
Neon confirmation dialog with the selected database, environment variable, and Connect and Redeploy button.
Neon confirmation dialog with the selected database, 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., NEON_DATABASE_URL if you already have a DATABASE_URL in use).

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

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