0
votes

I want to make a project, which uses Django as backend, PostgreSQL as database and FastAPI with Django REST Framework for REST. Don't see any problems with making a project just with Django, DRF and Postgres, but face with difficulties when speak about FastAPI and DRF at the same time. So there is no problem in connecting Postgres to Django, and there is no problem to make endpoints for DRF. But how can I connect fastapi? Where to place endpoints and how to run all this stuff together? In some examples I saw that FastAPI isntance is initiated in WSGI.py and then server runs from calling commands such like this:

uvicorn goatfish.wsgi:app

But i am not sure that it works like this when I mix more than only Django and FastAPI. I want to use FastAPI for optical character recongnition and DRF for user registration, logins etc. Are there any advices about making project with such a structure? Or maybe someone have a repository with such kind of project on github?

EDIT: Hope to see answers here, but for now I only see the solution in making classic Django + DRF app, then make FastAPI app with endpoints, run these apps on different ports and do some chain of actions: From django app we load an image to form and when we submit this form we send POST request to FastAPI endpoint, which will run OCR process and then return JSON with recognized text and then will send this JSON to the Django Callback endpoint, which will process it and save to the database. What do you think about such thing?

2

2 Answers

0
votes

Well, so after few days of thinking about I decided, that there is no sense in a question which I asked :) Here we should talk about microservice architecture, where such kind of problem just doesn't exist. All we need is to make as much services as we need in our project using any framework (Django, FastAPI, Flask, Ruby etc.) and make connections between them. As example I can run my main Django server on port 8000, my FastAPI server on port 5000 and my DRF service on port 6000. And then I can just do whatever I want from my main Django server making requests to endpoints of FastAPI and DRF. So that's very simple example, now I'm diving deeper into microservice architecturing, but that's definitely what I need.

0
votes

I think, you may:

  1. Mix of fastapi+django. But this is only for replace DRF and use fastapi as rest framework.
  2. Microservices. You may to run Django on one port, fastapi - another. And both may to use one shared database.
  3. Mircoservices. All from point 2, but some api tasks (for example sign-in/sign-up) on Django and another - on fastapi.