Skip to content

Neon Integration

  1. Navigate to Integrations in your team settings
  2. Click Connect on the Neon integration
  3. You’ll be redirected to Neon to authorize FastAPI Cloud
  4. 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 Storage tab in the app details
  2. Select the Neon integration
  3. Choose your project (if you belong to multiple Neon organizations, select the organization first)
  4. Choose a branch
  5. Choose a database
  6. 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., 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