A minimal FastAPI implementation for Django !

Overview

Caution!!!

This project is in early developing stage. So use it at you own risk.

Bug reports / Fix PRs are welcomed.

Installation

pip install django-mini-fastapi

Live demo provided by Gitpod

Click the button below and launch a free live demo server via Gitpod

Gitpod ready-to-code

If the button doesn't show up, you clould also use below link directly

https://gitpod.io/#https://github.com/tokikanno/django-mini-fastapi

After Gitpod launched, wait a while for the auto execution of make intro command Then you could using VScode remote explorer for opening the intro demo server in your browser.

image

What is django-mini-fastapi ?

A minimal FastAPI implementation for Django !

This project reused more than 95% codes from FastAPI. I just did minimal necessary modifications for making it working under Django.

So basicly you can read documents from FastAPI for knowing how to use this module. (Except features metioned in Features currently not work section) The difference between django-mini-fastapi and FastAPI is how you import and mount it.

# This is how you declear OpenAPI endpoint in FastAPI
from typing import Optional

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def read_root():
    return {"Hello": "World"}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: Optional[str] = None):
    return {"item_id": item_id, "q": q}

Above is the quick start sample in FastAPI document, which should be re-written like below

# This is how you do the same thing in django-mini-fastapi
from typing import Optional
from django_mini_fastapi import OpenAPI

app = OpenAPI()

@app.get("/")
def read_root():
    return {"Hello": "World"}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: Optional[str] = None):
    return {"item_id": item_id, "q": q}

And you should mount the API endpoint via Django url pattern mechanism by calling app.as_django_url_pattern()

urlpatterns = [
    # use as_django_url_pattern() for mounting API endpoint into Django url parser
    app.as_django_url_pattern(),
]

And usually you won't want to mount API endpoint in / for a Django project. You could pass the root_path parameter to OpenAPI init function for changing the mount point.

app = OpenAPI(root_path='/api')

For fully working example script, please see demo/intro.py

You can also type

make intro

for starting test intro server.

Why do you make this? Can't you just use FastAPI directly?

I'm a big fan of FastAPI. It's elegant and saves lots of doc maintaince & API spec communication costs for me.

But I'm maintaing huge legacy projects built by Django framework. It will take massive resources for porting it onto FastAPI.

So I decided to modifiy FastAPI for making it working under Django, then I could instantly get the benefits from FastAPI without doing migrations for my legacy projects.

Who should use this?

People who like the way FastAPI works but don't want to do full system rewrite from Django to FastAPI

Features currently work

  • Auto OpenAPI schema/document generation from Python function declaration
  • Auto request parameter validation
  • Dependencies system

Features currently not work

  • Auto OpenAPI parameters parsing & processing
    • Callback function delcearation (WIP)
    • Security scopes (Evaluating/Planning)
  • WebSocket endpoints (Not in priority)
  • Backgournd tasks (Not in priority)
You might also like...
Boilerplate code for quick docker implementation of REST API with JWT Authentication using FastAPI, PostgreSQL and PgAdmin ⭐

FRDP Boilerplate code for quick docker implementation of REST API with JWT Authentication using FastAPI, PostgreSQL and PgAdmin ⛏ . Getting Started Fe

Easy and secure implementation of Azure AD for your FastAPI APIs 🔒

FastAPI-Azure-auth Azure AD Authentication for FastAPI apps made easy. 🚀 Description FastAPI is a modern, fast (high-performance), web framework for

A dynamic FastAPI router that automatically creates CRUD routes for your models
A dynamic FastAPI router that automatically creates CRUD routes for your models

⚡ Create CRUD routes with lighting speed ⚡ A dynamic FastAPI router that automatically creates CRUD routes for your models

Adds simple SQLAlchemy support to FastAPI

FastAPI-SQLAlchemy FastAPI-SQLAlchemy provides a simple integration between FastAPI and SQLAlchemy in your application. It gives access to useful help

Opinionated set of utilities on top of FastAPI

FastAPI Contrib Opinionated set of utilities on top of FastAPI Free software: MIT license Documentation: https://fastapi-contrib.readthedocs.io. Featu

Reusable utilities for FastAPI

Reusable utilities for FastAPI Documentation: https://fastapi-utils.davidmontague.xyz Source Code: https://github.com/dmontagu/fastapi-utils FastAPI i

This code generator creates FastAPI app from an openapi file.

fastapi-code-generator This code generator creates FastAPI app from an openapi file. This project is an experimental phase. fastapi-code-generator use

FastAPI framework plugins

Plugins for FastAPI framework, high performance, easy to learn, fast to code, ready for production fastapi-plugins FastAPI framework plugins Cache Mem

Prometheus exporter for Starlette and FastAPI

starlette_exporter Prometheus exporter for Starlette and FastAPI. The middleware collects basic metrics: Counter: starlette_requests_total Histogram:

Comments
  • replace force_text with force_str.

    replace force_text with force_str.

    The smart_text() and force_text() aliases (since Django 2.0) of smart_str() and force_str() are deprecated. Ignore this deprecation if your code supports Python 2 as the behavior of smart_str() and force_str() is different there.

    ref. https://docs.djangoproject.com/en/4.0/releases/3.0/#django-utils-encoding-force-text-and-smart-text

    opened by hanyichiu 0
Owner
toki
toki
:rocket: CLI tool for FastAPI. Generating new FastAPI projects & boilerplates made easy.

Project generator and manager for FastAPI. Source Code: View it on Github Features ?? Creates customizable project boilerplate. Creates customizable a

Yagiz Degirmenci 1k Jan 2, 2023
Simple FastAPI Example : Blog API using FastAPI : Beginner Friendly

fastapi_blog FastAPI : Simple Blog API with CRUD operation Steps to run the project: git clone https://github.com/mrAvi07/fastapi_blog.git cd fastapi-

Avinash Alanjkar 1 Oct 8, 2022
Пример использования GraphQL Ariadne с FastAPI и сравнение его с GraphQL Graphene FastAPI

FastAPI Ariadne Example Пример использования GraphQL Ariadne с FastAPI и сравнение его с GraphQL Graphene FastAPI - GitHub ###Запуск на локальном окру

ZeBrains Team 9 Nov 10, 2022
Sample-fastapi - A sample app using Fastapi that you can deploy on App Platform

Getting Started We provide a sample app using Fastapi that you can deploy on App

Erhan BÜTE 2 Jan 17, 2022
Flask-vs-FastAPI - Understanding Flask vs FastAPI Web Framework. A comparison of two different RestAPI frameworks.

Flask-vs-FastAPI Understanding Flask vs FastAPI Web Framework. A comparison of two different RestAPI frameworks. IntroductionIn Flask is a popular mic

Mithlesh Navlakhe 1 Jan 1, 2022
FastAPI Server Session is a dependency-based extension for FastAPI that adds support for server-sided session management

FastAPI Server-sided Session FastAPI Server Session is a dependency-based extension for FastAPI that adds support for server-sided session management.

DevGuyAhnaf 5 Dec 23, 2022
fastapi-admin2 is an upgraded fastapi-admin, that supports ORM dialects, true Dependency Injection and extendability

FastAPI2 Admin Introduction fastapi-admin2 is an upgraded fastapi-admin, that supports ORM dialects, true Dependency Injection and extendability. Now

Glib 14 Dec 5, 2022
Code Specialist 27 Oct 16, 2022
Fastapi-ml-template - Fastapi ml template with python

FastAPI ML Template Run Web API Local $ sh run.sh # poetry run uvicorn app.mai

Yuki Okuda 29 Nov 20, 2022
🐞 A debug toolbar for FastAPI based on the original django-debug-toolbar. 🐞

Debug Toolbar ?? A debug toolbar for FastAPI based on the original django-debug-toolbar. ?? Swagger UI & GraphQL are supported. Documentation: https:/

Dani 74 Dec 30, 2022