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.txtfile 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 python3or download from python.org - Linux: Run
sudo apt install python3 python3-pip(Ubuntu/Debian) orsudo dnf install python3(Fedora)
Once Python is installed, create a project folder and set up a virtual environment:
mkdir my-fastapi-app && cd my-fastapi-app
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install fastapi uvicornIf 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:
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:
fastapi==0.115.6
uvicorn[standard]==0.32.0Create Procfile (no file extension):
web: uvicorn main:app --host 0.0.0.0 --port 8080This 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:
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
- Go to console.outplane.com
- Sign in with your GitHub account
- 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
Dockerfilein 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
mainor 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:
- Queued → Waiting for resources
- Building → Installing dependencies from requirements.txt
- Deploying → Starting your FastAPI application
- 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:
uvicorn main:app --host 0.0.0.0 --port 8080 --workers 4Out 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:
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:
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:
- Go to Databases in the sidebar
- Click Create Database
- Select PostgreSQL version and region
- Copy the connection URL
Add the connection URL as an environment variable:
DATABASE_URL=postgresql+asyncpg://user:password@host/databaseThen use it in your FastAPI app with SQLAlchemy:
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):
passCustom Domain Setup
Replace the default .outplane.app URL with your own domain:
- Navigate to Domains
- Click Map Domain
- Enter your domain (e.g.,
api.yourdomain.com) - 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:
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:
- Connect your GitHub repository
- Configure port (8080) and environment variables
- 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.