FastAPI-Restly#

CI Python License Coverage

_images/restly-cat.png

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 to 1.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#

Documentation#

Getting Started

Fast path from zero to a working REST API.

Getting Started
Tutorial

Build a complete blog API in two parts: generated CRUD, then customization.

Tutorial
Class-Based Views

How subclassable views make the override model work.

Class-Based Views
How Overrides Work

The three tiers behind every CRUD verb, and which one to override.

How Overrides Work: The Three Tiers
How-To Guides

Task-focused guides, from adoption in an existing app to deployment.

How-To Guides
Examples

Complete sample applications from a tiny API to a production-shaped service.

Examples
API Reference

Generated endpoints, all public symbols, query parameters, and autodoc.

API Reference
About

History, design goals, and why this framework exists.

About FastAPI-Restly
Deploying

Production engine config, Alembic migrations, and an ASGI checklist.

Deploying