FastAPI-Restly#
FastAPI-Restly (fr) is a REST framework for FastAPI, backed by SQLAlchemy 2.0
and Pydantic v2. Views are real Python classes: share behavior with inheritance
and mixins, and override the one operation you need.
Status:
0.7.0— public beta, after four years of internal use. Expect small breaking changes in deeper extension points on the way to1.0.0; see the changelog.
Quick Start#
pip install "fastapi-restly[standard]" aiosqlite
A SQLAlchemy model and a four-line view class — complete and runnable:
from contextlib import asynccontextmanager
import fastapi_restly as fr
from fastapi import FastAPI
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
fr.configure(async_database_url="sqlite+aiosqlite:///app.db")
class Base(DeclarativeBase):
pass
class User(Base):
__tablename__ = "user"
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str]
email: Mapped[str]
active: Mapped[bool] = mapped_column(default=True)
@asynccontextmanager
async def lifespan(_app: FastAPI):
await fr.db.async_create_all(Base) # dev tables; use Alembic in production
yield
app = FastAPI(lifespan=lifespan)
@fr.include_view(app)
class UserView(fr.AsyncRestView):
prefix = "/users"
model = User
That view exposes these routes, with schemas generated from the model:
GET /users/ # list users — filter, sort, paginate via URL params
POST /users/ # create a user
GET /users/{id} # read one user
PATCH /users/{id} # partially update one user
DELETE /users/{id} # delete one user
Because the view is a class, changing one behavior means overriding one
method — routing, validation, and the commit stay framework-owned. Add to
UserView:
async def delete(self, obj):
obj.active = False # deactivate instead of removing the row
DELETE /users/{id} now soft-disables (the row stays readable, with
active: false); the other four routes are untouched.
Run it with fastapi dev main.py. Getting Started walks
through the same flow step by step — install details, explicit schemas, and a
first test.
Features#
Generated REST endpoints — GET, POST, PATCH, DELETE with minimal boilerplate
True class-based views — inheritance, mixins, and method overrides
Explicit override points — every CRUD verb split into route shell, request handler, and business method
React Admin ready —
AsyncReactAdminViewspeaksra-data-simple-restSQLAlchemy 2.0 support — async-first with modern patterns
Pydantic v2 integration — validation and serialization for public contracts
Automatic schema generation — read, create, and update schemas generated automatically
List parameters — filter, sort, and paginate from a stable URL dialect generated from the response schema
Relationship support — handle foreign keys and nested objects
Testing utilities — built-in test helpers with savepoint isolation
Documentation#
Fast path from zero to a working REST API.
Build a complete blog API in two parts: generated CRUD, then customization.
How subclassable views make the override model work.
The three tiers behind every CRUD verb, and which one to override.
Task-focused guides, from adoption in an existing app to deployment.
Complete sample applications from a tiny API to a production-shaped service.
Generated endpoints, all public symbols, query parameters, and autodoc.
History, design goals, and why this framework exists.
Production engine config, Alembic migrations, and an ASGI checklist.