Railway

Deploy FastAPI - PostgreSQL

A comprehensive FastAPI and PostgreSQL template.

Deploy FastAPI - PostgreSQL

/var/lib/postgresql/data

Just deployed

Overview

The most complete FastAPI + PostgreSQL template on Railway — fully async, production-ready, and built with modern Python best practices. Skip weeks of boilerplate and start building your API in minutes.

Whether you're prototyping a side project or scaffolding a production service, this template gives you everything you need out of the box: async database access, authenticated API docs, structured project layout, and one-click deployment.

Why This Template?

  • Fully async from top to bottom: Every endpoint, CRUD operation, and database call is non-blocking — no thread pool bottlenecks, no mixed sync/async confusion. Just clean, fast async Python.

  • SQLAlchemy 2.0 + PostgreSQL: Modern ORM with select() queries, async_sessionmaker, and native UUID support. Auto-creates tables on startup, disposes connections on shutdown — zero manual setup.

  • Authenticated API docs: /docs and /redoc are protected behind session-based login using a pure ASGI middleware (no BaseHTTPMiddleware overhead). Your API documentation stays private until you're ready to share.

  • Production-grade performance: ORJSONResponse for fast serialization, uvloop + httptools for maximum throughput, GZIP compression, and a tuned thread pool (100 threads) for mixed workloads.

  • Modern Python tooling: Managed with uv and pyproject.toml — fast, reproducible installs with no dependency conflicts. Python 3.12, Pydantic v2, and clean src/ project layout.

  • Ready to extend: Clean separation between API endpoints, service layer, models, and schemas. Add new resources by following the existing messages pattern — no guesswork needed.

What's Included

  • FastAPI with async CRUD endpoints (Create, Read, Update, Delete)
  • PostgreSQL with SQLAlchemy 2.0 async engine
  • Pydantic v2 request/response validation
  • Session-based authentication for API docs
  • Environment-driven configuration (.env.example provided)
  • Docker multi-stage build
  • Async test suite with pytest
  • Locust load testing configuration

Quick Start

  1. Click Deploy to provision your FastAPI app + PostgreSQL database
  2. Set USER_NAME and PASSWORD environment variables for API doc access
  3. Visit your deployment URL — your API is live

Learn More


Template Content

More templates in this category

View Template
caring-vibrancy
Deploy and Host caring-vibrancy with Railway

baleocho
View Template
NEW
Flask WebSocket Chat
Single file, realtime multi-user websocket chat using flask-socketio

Clement Ochieng
View Template
Mellow Vue
A full-stack Vue app with The Boring JavaScript Stack.

Sailscasts HQ