Skip to main content

FastAPI MVT

A batteries-included project framework for FastAPI — structured, fast to start, and built for developers who want Django's ergonomics with FastAPI's performance.

Python FastAPI License: MIT Docs


Overview

FastAPI MVT is a project scaffolding framework built on top of FastAPI.

It gives you a full project skeleton the moment you run one command — with authentication, database, WebSocket, signals, middleware, and CLI management all wired together and ready to use.

You write your business logic. The framework handles the plumbing.


Features

Feature Description
MVT Pattern Model → View → Template architecture familiar to Django developers
JWT Authentication Built-in /auth router with register, login, logout, refresh, and /me endpoints
SQLAlchemy + Alembic Async-ready ORM with full migration support via makemigrations / migrate
Signals Django-style ORM signals (pre_save, post_save, pre_delete, post_delete) wired automatically via SQLAlchemy events
WebSocket Manager Group-aware connection manager with optional Redis channel backend for multi-process scaling
Security Middleware CORS, security headers, rate limiting, and SQL injection protection out of the box
App Registry Auto-discovery system for routers, models, and signals across multiple apps
CLI Management startproject, startapp, makemigrations, migrate, checkmigrations commands

Tech Stack


Installation

pip install fastapi-mvt

Or install from source:

git clone https://github.com/yourusername/fastapi-mvt
cd fastapi-mvt
pip install -e .

Quick Start

1. Create a new project

fastapi-mvt startproject myproject
cd myproject

2. Create an app

fastapi-mvt startapp blog

3. Run migrations

fastapi-mvt makemigrations
fastapi-mvt migrate

4. Start the server

uvicorn myproject.asgi:app --reload

Project Structure

After running startproject, you get:

myproject/
├── manage.py               # CLI entry point
├── .env                    # Environment variables
├── myproject/
│   ├── settings.py         # Project settings (INSTALLED_APPS, DB, etc.)
│   ├── urls.py             # Root router
│   └── asgi.py             # ASGI application entry point
├── apps/
│   └── blog/               # An example app (via startapp)
│       ├── models.py       # SQLAlchemy models
│       ├── views.py        # FastAPI route handlers
│       ├── schemas.py      # Pydantic schemas
│       ├── signals.py      # Signal receivers
│       └── router.py       # APIRouter definition
└── migrations/
    └── versions/           # Alembic migration files

Core Concepts

Authentication

FastAPI MVT ships a plug-and-play JWT auth system. Configure it once in settings.py:

from fastapi_mvt.auth import configure_auth, AuthConfig

configure_auth(AuthConfig(
    secret_key="your-secret-key",
    user_model="apps.accounts.models.User",   # omit to use built-in DefaultAuthUser
))

Then include the built-in auth router:

from fastapi import FastAPI
from fastapi_mvt.auth import auth_router

app = FastAPI()
app.include_router(auth_router)

Available endpoints:

Method Path Description
POST /auth/register Create account, returns token pair
POST /auth/login Authenticate, returns token pair
POST /auth/logout Revoke access token
POST /auth/refresh Exchange refresh token for new access token
GET /auth/me Return authenticated user identity

Protect your own routes with the get_current_user dependency:

from fastapi import Depends
from fastapi_mvt.auth import get_current_user

@router.get("/profile")
def profile(user=Depends(get_current_user)):
    return {"id": user.id, "email": user.email}

Signals

Signals fire automatically when SQLAlchemy models are saved or deleted — no manual .send() calls needed inside views.

from fastapi_mvt.core.signals import receiver, post_save
from apps.blog.models import Post

@receiver(post_save, sender=Post)
async def on_post_saved(sender, instance, created, **kwargs):
    if created:
        print(f"New post published: {instance.title}")

Register signals during startup:

from fastapi_mvt.core.signals import register_all_model_signals
from myproject.db import Base

register_all_model_signals(Base)

Available signals: pre_save, post_save, pre_delete, post_delete, post_init


WebSocket

A group-aware WebSocket connection manager is included. For multi-process deployments, swap in the Redis backend:

from fastapi_mvt.utils.websocket import ConnectionManager, RedisChannelBackend
import redis.asyncio as aioredis

redis_client = aioredis.from_url("redis://localhost")
manager = ConnectionManager(channel_backend=RedisChannelBackend(redis_client))

Use in route handlers:

from fastapi import WebSocket
from fastapi_mvt.utils.websocket import manager

@app.websocket("/ws/{room}")
async def websocket_endpoint(websocket: WebSocket, room: str):
    conn_id = await manager.connect(websocket, group=room)
    try:
        while True:
            data = await websocket.receive_text()
            await manager.send_to_group(room, {"message": data})
    finally:
        await manager.disconnect(conn_id)

Middleware

Security middleware is applied automatically. You can also configure it manually:

from fastapi_mvt.middleware import setup_security_middleware, setup_cors_middleware

setup_cors_middleware(app, origins=["https://example.com"])
setup_security_middleware(app)

Built-in middleware:

  • SecurityHeadersMiddleware — adds X-Content-Type-Options, X-Frame-Options, HSTS, CSP, and more
  • SQLInjectionProtectionMiddleware — blocks common SQL injection patterns in request parameters
  • RateLimitMiddleware — request-rate throttling per IP
  • CustomMiddleware — base class for your own middleware

App Registry

Register apps in settings.py and the framework auto-discovers their routers, models, and signals:

INSTALLED_APPS = [
    "apps.blog",
    "apps.accounts",
]

CLI Reference

Command Description
fastapi-mvt startproject <name> Scaffold a new project
fastapi-mvt startapp <name> Scaffold a new app inside a project
fastapi-mvt makemigrations [app] Generate Alembic migration from model changes
fastapi-mvt migrate Apply pending migrations to the database
fastapi-mvt checkmigrations Report empty or no-op migration files

Configuration

All settings live in your project's settings.py. Key options:

# Database
DATABASE_URL = "sqlite+aiosqlite:///./db.sqlite3"
# DATABASE_URL = "postgresql+asyncpg://user:pass@localhost/dbname"

# Auth
SECRET_KEY = "change-me-in-production"
ACCESS_TOKEN_EXPIRE_MINUTES = 30
REFRESH_TOKEN_EXPIRE_DAYS = 7

# Apps
INSTALLED_APPS = [
    "apps.blog",
    "apps.accounts",
]

# CORS
CORS_ORIGINS = ["http://localhost:3000"]

Documentation

Full documentation is available at https://odaithalji.gitbook.io/fastapi


License

MIT License — see LICENSE for details.

Metadata

Release files for fastapi-mvt 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-mvt 0.1.3
File Size Uploaded Provenance Actions
fastapi_mvt-0.1.3.tar.gz 48.7 kB With provenance Details for fastapi_mvt-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-mvt 0.1.3
File Interpreter ABI Platform Actions
fastapi_mvt-0.1.3-py3-none-any.whl Python 3 none any Details for fastapi_mvt-0.1.3-py3-none-any.whl

Total release size: 102.5 kB

Release files / fastapi_mvt-0.1.3.tar.gz

Download URL fastapi_mvt-0.1.3.tar.gz
Size 48.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6266b86cb444d08e22e64d9968cf7e508fff08c1439d757ef4028433ad83542c
BLAKE2b-256 checksum
How to use checksums
dd8c07c0acbf59b6553e07ba1a559731ec58d2ac90a660110d21f6355e5a463b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 14, 2026.

Transparency log

Release files / fastapi_mvt-0.1.3-py3-none-any.whl

Download URL fastapi_mvt-0.1.3-py3-none-any.whl
Size 53.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
616e15d41efff38e7b801b4ab0ddede5aa93d25552b313345cb38df2cdaba9eb
BLAKE2b-256 checksum
How to use checksums
6de7c808b48a69d10cd026268da9947430f5eb10204d5c566f9b495336c3dc23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 14, 2026.

Transparency log

Security for fastapi-mvt 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for fastapi_mvt-0.1.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 14, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page