Package: django-mini-fastapi
Caution!!!This is a minimal FastAPI port for Django, not all of FastAPI functionalities are supported.Please seeFeatures currently workandFeatures currently not worksections to evaluate if all the functionalities you need are ported.Also, bug reports / Fix PRs are welcomed.Installationpipinstalldjango-mini-fastapiLive demo provided by GitpodClick the button below and launch a free live demo server via GitpodIf the button doesn't show up, you clould also use below link directlyhttps://gitpod.io/#https://github.com/tokikanno/django-mini-fastapiAfter Gitpod launched, wait a while for the auto execution ofmake introcommand
Then you could using VScode remote explorer for opening the intro demo server in your browser.What isdjango-mini-fastapi?A minimal FastAPI implementation for Django !This project reused more than 95% codes fromFastAPI. 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 inFeatures currently not worksection)
The major difference between django-mini-fastapi and FastAPI is how you import and mount it.# This is how you declear OpenAPI endpoint in FastAPIfromtypingimportOptionalfromfastapiimportFastAPIapp=FastAPI()@app.get("/")defread_root():return{"Hello":"World"}@app.get("/items/{item_id}")defread_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-fastapifromtypingimportOptionalfromdjango_mini_fastapiimportOpenAPIapp=OpenAPI()@app.get("/")defread_root():return{"Hello":"World"}@app.get("/items/{item_id}")defread_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 callingapp.as_django_url_pattern()urlpatterns=[# use as_django_url_pattern() for mounting API endpoint into Django url parserapp.as_django_url_pattern(),]And usually you won't want to mount API endpoint in/for a Django project. You could pass theroot_pathparameter to OpenAPI init function for changing the mount point.app=OpenAPI(root_path='/api')For fully working example script, please seedemo/intro.pyYou can also typemakeintrofor 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 FastAPIFeatures currently workAuto OpenAPI schema/document generation from Python function declarationAuto request parameter validationDependencies systemAuthentication (Security dependencies)Features currently not workAuto OpenAPI parameters parsing & processingCallback function delcearation (WIP)Security dependencies (Evaluating/Planning)(done)WebSocket endpoints (Not in priority)Backgournd tasks (Not in priority, we still use celery even using the real FastAPI. Background task execution function in FastAPI isn't very suitable for serious tasks.)