Skip to main content

A Django-inspired MVT framework built on top of FastAPI

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_mvt-0.1.1.tar.gz (48.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_mvt-0.1.1-py3-none-any.whl (53.9 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_mvt-0.1.1.tar.gz.

File metadata

  • Download URL: fastapi_mvt-0.1.1.tar.gz
  • Upload date:
  • Size: 48.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fastapi_mvt-0.1.1.tar.gz
Algorithm Hash digest
SHA256 16b9084530b0bba2f03d24ba18fc76680a5514a6c0c69a2cbf869cf5653a49f8
MD5 530319798819830f5cf9827e527ba5bf
BLAKE2b-256 99c27433844f3411521f146e8242bac2fc47d6fc12f024468e29b22b02e5aacd

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_mvt-0.1.1.tar.gz:

Publisher: workflow.yml on OdaiAhmed99/fastapi-mvt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastapi_mvt-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: fastapi_mvt-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 53.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fastapi_mvt-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2cde63b976bdaf9d77d270d3b10c83730f6c66af82f23bf7e45889e7b40f7a4b
MD5 57bdae9652df9b0c62dff936f0df9302
BLAKE2b-256 4364f6f6db4e92dc2053ad72f177732bb174347a255946f72ab155afb5bd06fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_mvt-0.1.1-py3-none-any.whl:

Publisher: workflow.yml on OdaiAhmed99/fastapi-mvt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page