Out Plane LogoOut Plane

FastAPI

Step-by-step guide to deploy a FastAPI Python application on Out Plane

This guide walks you through deploying a FastAPI application on Out Plane using Git-driven deployment with a Dockerfile.

Prerequisites

  • An Out Plane account
  • A GitHub account
  • Python 3.10+ installed on your machine
  • Git installed on your machine

Create the FastAPI App

Create a new directory for your project:

mkdir my-fastapi-app
cd my-fastapi-app

Create a virtual environment and activate it:

python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

Install FastAPI and Uvicorn:

pip install fastapi "uvicorn[standard]"

Create requirements.txt:

pip freeze > requirements.txt

Create a file called main.py:

from fastapi import FastAPI

app = FastAPI(title="My FastAPI App")

@app.get("/")
async def root():
    return {"message": "Hello from Out Plane"}

@app.get("/health")
async def health():
    return {"status": "healthy"}

Create the Dockerfile

Create a file called Dockerfile in your project root:

FROM python:3.12-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE 8000

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

Create a .dockerignore file:

__pycache__
*.pyc
.git
.env
venv
.venv
*.md
.DS_Store

Test Locally

Run the development server:

uvicorn main:app --reload

Open http://localhost:8000 in your browser. You should see the JSON response.

FastAPI automatically generates interactive API documentation at http://localhost:8000/docs.

Push to GitHub

Initialize a Git repository and push to GitHub:

git init
git add .
git commit -m "Initial commit"
git remote add origin [email protected]:YOUR_USERNAME/my-fastapi-app.git
git branch -M main
git push -u origin main

Replace YOUR_USERNAME with your GitHub username.

Deploy on Out Plane

Step 1: Install GitHub App

  1. Go to console.outplane.com
  2. Navigate to Applications from the sidebar
  3. Click Deploy Application
  4. If prompted, click Install GitHub App
  5. Select which repositories Out Plane can access
  6. Click Install and you'll be redirected back

Step 2: Select Repository

  1. Find your repository in the list
  2. Click to select it
  3. Choose the branch to deploy (default: main)
  4. Set Root Directory to /

Step 3: Configure Build

SettingValue
Build MethodSelect Dockerfile
Application NameEnter a unique name (e.g., my-fastapi-app)
Port8000

Step 4: Select Resources

InstancevCPURAMRecommended For
op-200.5512 MBDevelopment, small APIs
op-4611 GBProduction APIs
op-8222 GBHeavy workloads

Step 5: Configure Scaling

  • Min Scale: Set to 1 for always-on, or 0 for scale-to-zero
  • Max Scale: Set based on expected traffic

Step 6: Environment Variables (Optional)

Click Add Variable to add environment variables:

KeyValue
DATABASE_URLYour database connection string
SECRET_KEYYour application secret

Step 7: Deploy

  1. Review your configuration
  2. Click Create Application
  3. Wait for the build to complete (typically 2-3 minutes)

Step 8: Access Your App

Once the deployment status shows Ready:

  1. Go to the application Overview tab
  2. Find your domain: my-fastapi-app.outplane.app
  3. Click to open your live application
  4. Access API docs at my-fastapi-app.outplane.app/docs

Adding a Database

Step 1: Create a Database

  1. Go to Databases in the sidebar
  2. Click Create Database
  3. Choose a name, PostgreSQL version, and region
  4. Click Create Database

Step 2: Get Connection String

  1. Click on your database
  2. In the Overview tab, find the connection string
  3. Copy the connection URL

Step 3: Connect from FastAPI

Install the async PostgreSQL driver:

pip install asyncpg sqlalchemy
pip freeze > requirements.txt

Create a database connection:

from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from sqlalchemy.orm import sessionmaker
import os

DATABASE_URL = os.environ.get("DATABASE_URL")

# Convert postgres:// to postgresql+asyncpg://
if DATABASE_URL and DATABASE_URL.startswith("postgres://"):
    DATABASE_URL = DATABASE_URL.replace("postgres://", "postgresql+asyncpg://", 1)

engine = create_async_engine(DATABASE_URL)
async_session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)

Step 4: Add Environment Variable

  1. Go to your application in Out Plane
  2. Click SettingsEnvironment
  3. Add DATABASE_URL with your connection string
  4. Click Save and redeploy

Production Dockerfile

For production, use Gunicorn with Uvicorn workers:

FROM python:3.12-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt gunicorn

COPY . .

EXPOSE 8000

CMD ["gunicorn", "main:app", "-w", "4", "-k", "uvicorn.workers.UvicornWorker", "-b", "0.0.0.0:8000"]

Automatic Deployments

Push to your branch to trigger automatic deployments:

git add .
git commit -m "Add new endpoint"
git push origin main

Next Steps

Buildpack alternative: Instead of Dockerfile, select Buildpack and add a Procfile with: web: uvicorn main:app --host 0.0.0.0 --port $PORT