Back to Blog
Tutorial

How to Deploy a FastAPI Application in 1 Minute

Daniel Brooks5 min read
How to Deploy a FastAPI Application in 1 Minute

FastAPI is the fastest-growing Python web framework, built for high-performance APIs with automatic documentation. Deploying FastAPI to production typically requires ASGI server configuration, SSL certificates, and infrastructure setup.

With Out Plane, you can deploy your FastAPI application in under a minute. This guide shows you exactly how.

What You'll Need

Before starting, make sure you have:

  • Python 3.10+ installed on your machine
  • A GitHub account
  • A FastAPI application in a GitHub repository
  • A requirements.txt file with your dependencies

Don't have Python installed? Download it from python.org:

  • Windows: Download the installer and check "Add Python to PATH" during installation
  • macOS: Use brew install python3 or download from python.org
  • Linux: Run sudo apt install python3 python3-pip (Ubuntu/Debian) or sudo dnf install python3 (Fedora)

Once Python is installed, create a project folder and set up a virtual environment:

bash
mkdir my-fastapi-app && cd my-fastapi-app
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install fastapi uvicorn

If you don't have a FastAPI app yet, use our example below.

Quick Start: Sample FastAPI Application

Here's a minimal FastAPI application you can use. Create these three files in your repository:

Create main.py:

python
from fastapi import FastAPI

app = FastAPI(
    title="My FastAPI App",
    description="Deployed on Out Plane",
    version="1.0.0"
)

@app.get("/")
async def root():
    return {
        "message": "Hello from FastAPI!",
        "status": "running"
    }

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

@app.get("/items/{item_id}")
async def read_item(item_id: int, q: str = None):
    return {"item_id": item_id, "query": q}

Create requirements.txt:

text
fastapi==0.115.6
uvicorn[standard]==0.32.0

Create Procfile (no file extension):

text
web: uvicorn main:app --host 0.0.0.0 --port 8080

This tells Buildpacks how to start your application with the Uvicorn ASGI server.

Push this code to a GitHub repository, and you're ready to deploy.

Optional: Add a Dockerfile

If you prefer full control over the build process, create a Dockerfile instead of using Buildpacks:

dockerfile
FROM python:3.12-slim

WORKDIR /app

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

COPY . .

EXPOSE 8080

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080", "--workers", "4"]

With a Dockerfile, select Dockerfile as your build method in the next step. Without one, select Buildpacks and Out Plane handles everything automatically.

Deploy in 3 Steps

Step 1: Connect Your Repository

  1. Go to console.outplane.com
  2. Sign in with your GitHub account
  3. Select your FastAPI repository from the list

Out Plane automatically detects Python applications and configures the build process using Buildpacks.

Step 2: Configure Your Application

Configure the following settings in the create application form:

Build Method

Select how Out Plane should build your application:

  • Buildpacks (Recommended): Automatically detects Python and installs dependencies from requirements.txt. No additional configuration needed.
  • Dockerfile: Use this if you have a custom Dockerfile in your repository for full control over the build process.

For most FastAPI applications, Buildpacks is the easiest option.

Basic Settings

  • Port: Set to 8080
  • Branch: Select main or your preferred branch
  • Region: Choose the region closest to your users

Environment Variables (Optional)

If your application uses environment-specific configuration, add them here. For our simple example, no environment variables are required.

For more complex applications, you might add variables like database URLs or API keys using the Add button or Raw Edit for bulk entry.

Step 3: Deploy

Click Deploy Application and watch the build process:

  1. Queued → Waiting for resources
  2. Building → Installing dependencies from requirements.txt
  3. Deploying → Starting your FastAPI application
  4. Ready → Your app is live

Once the status shows Ready, your application is live. You can find your application URL at the top of the deployment page. Click the URL to open your FastAPI app in a new tab. SSL is automatically configured.

Access API Documentation

FastAPI automatically generates interactive API documentation. After deployment, access:

  • Swagger UI: https://your-app.outplane.app/docs
  • ReDoc: https://your-app.outplane.app/redoc
  • OpenAPI JSON: https://your-app.outplane.app/openapi.json

These endpoints work immediately with no additional configuration.

Production Best Practices

Use Uvicorn with Workers

For production, run Uvicorn with multiple workers to handle concurrent requests:

bash
uvicorn main:app --host 0.0.0.0 --port 8080 --workers 4

Out Plane's Buildpacks automatically detect Uvicorn in your requirements.txt and configure it properly.

Configure Workers

For better performance under load, customize the number of workers. A common formula is (2 × CPU cores) + 1.

If you need custom worker configuration, use a Dockerfile instead of Buildpacks for full control over the start command.

Async Database Connections

FastAPI excels at async operations. Use async database drivers for optimal performance:

python
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession

# Use asyncpg for PostgreSQL
DATABASE_URL = "postgresql+asyncpg://user:pass@host/db"
engine = create_async_engine(DATABASE_URL)

Environment-Based Configuration

Keep sensitive data out of your codebase with environment variables:

python
import os
from fastapi import FastAPI

app = FastAPI()

DATABASE_URL = os.environ.get("DATABASE_URL")
DEBUG = os.environ.get("DEBUG", "0") == "1"

Connecting a Database

Most FastAPI applications need a database. Out Plane provides managed PostgreSQL:

  1. Go to Databases in the sidebar
  2. Click Create Database
  3. Select PostgreSQL version and region
  4. Copy the connection URL

Add the connection URL as an environment variable:

text
DATABASE_URL=postgresql+asyncpg://user:password@host/database

Then use it in your FastAPI app with SQLAlchemy:

python
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker
from sqlalchemy.orm import DeclarativeBase
import os

DATABASE_URL = os.environ.get("DATABASE_URL")
engine = create_async_engine(DATABASE_URL, echo=True)
async_session = async_sessionmaker(engine, expire_on_commit=False)

class Base(DeclarativeBase):
    pass

Custom Domain Setup

Replace the default .outplane.app URL with your own domain:

  1. Navigate to Domains
  2. Click Map Domain
  3. Enter your domain (e.g., api.yourdomain.com)
  4. Add the DNS records shown to your domain registrar

SSL certificates are automatically provisioned once DNS propagates.

Monitoring Your Application

After deployment, monitor your FastAPI application:

  • Logs: View real-time application logs including Uvicorn access logs
  • Metrics: Track CPU, memory, and network usage
  • HTTP Logs: Analyze incoming requests, response times, and status codes

Access these from the sidebar in your application dashboard.

Troubleshooting

Application Won't Start

Check the port configuration. Make sure you set the port to 8080 in the application settings and your Uvicorn command matches.

Module Not Found Errors

Verify requirements.txt includes all dependencies. Run pip freeze > requirements.txt locally to capture all installed packages. Ensure uvicorn[standard] is included.

500 Internal Server Error

Check your application logs. Navigate to Logs in the sidebar to see Python tracebacks and error messages. FastAPI provides detailed error responses in development mode.

Slow Cold Starts

Optimize your imports. Heavy imports at application startup increase cold start times. Consider lazy loading for large dependencies like ML models.

CORS Issues

If your frontend can't connect, add CORS middleware:

python
from fastapi.middleware.cors import CORSMiddleware

app.add_middleware(
    CORSMiddleware,
    allow_origins=["https://yourdomain.com"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

Next Steps

Your FastAPI application is now deployed and running in production. Here's what to explore next:

  • Scale your application: Adjust instance types and auto-scaling settings for higher traffic
  • Set up CI/CD: Enable automatic deployments on every git push
  • Add monitoring: Integrate with external monitoring tools via Out Plane's metrics export
  • Enable background tasks: Use FastAPI's BackgroundTasks for async operations

Summary

Deploying a FastAPI application to Out Plane takes three steps:

  1. Connect your GitHub repository
  2. Configure port (8080) and environment variables
  3. Deploy and get your live URL with automatic API docs

No server configuration, no manual SSL setup, no infrastructure management. Automatic Swagger documentation at /docs works out of the box.

Ready to deploy your FastAPI application? Get started with Out Plane and receive $20 in free credit.


Tags

fastapi
python
deployment
tutorial
api
async

Start deploying in minutes

Connect your GitHub repository and deploy your first application today. $20 free credit. No credit card required.