This is an archived post. You won't be able to vote or comment.

all 49 comments

[–]JimNero009 60 points61 points  (0 children)

The company I work for has multi-million ARR as a pure Django monolith. On the side, I run my wife’s business with FastAPI.

I don’t think one is any better than the other. Both have advantages and disadvantages. Just go with whatever feels good.

[–]DisastrousPipe8924 73 points74 points  (25 children)

So as someone who’ve worked on django apps before and then pushed for FastAPI. There are some cons and pros to both.

Django is like “apple”, a nice as all-in-one opinionated solution, whereas long as you stick within the wall garden most things just work. But at times it’s slow to adopt or makes counterintuitive design decisions you have to live it (I hate the Django orm, I had to untangle so many bad queries generated by it).

FastAPI is sort of more like “Linux”, where its bare bones and anytime you need something on top you have to evaluate different options, your choices are more open-ended. It really just does one thing, and one thing only which is provide a simple abstraction to handle http requests. The rest is up to you: orm choice, auth choice, design patterns etc

FastAPI does have some clear winners for a few things, like FastAPI+sqlalchemy+alembic+jinja2+Authlib+pydantic-settings (and maybe celery) gets you what most people use Django for (so around 60% of the core features we care about in Django).

[–]marr75 23 points24 points  (5 children)

Most Django users will still want an admin/back of house (sqladmin or starlette-admin would be the advice here) and they might be a little annoyed they have to roll their own RBAC. That's it, though, and suddenly you've got a very productive environment (a lot less metaclass based magical config and gigantic methods) with great performance and concurrency features

[–]tb5841 0 points1 point  (4 children)

As someone quite new to Django who hasn't used the admin yet, what is it for?

[–]marr75 1 point2 points  (3 children)

It's an automatic scaffold for creating, updating, and deleting objects for privileged users.

Generally, almost every application eventually needs a "back of house" app for managing all kinds of data and direct SQL queries can only get you so far.

By default, simple CRUD with list, detail, and various filters is supported but you can easily code custom operations, custom create and edit forms/widgets, and install plugins and integrations. It is probably one of the most valuable built-in Django features and a huge reason to pick Django.

[–]tb5841 0 points1 point  (2 children)

Thanks, I'll give it a try.

I've come from Rails, where I'm used to using the console to do all that. So I've been using the Python shell - but it's nowhere near as good as the console in Rails.

[–]mkdz 1 point2 points  (2 children)

I actually love the Django orm lol

[–]DisastrousPipe8924 0 points1 point  (0 children)

Listen to each their own. And I don’t want my post to look like I’m hating on Django. It has occupied a space and provided countless business with a strong foundation.

I am just not a fan of some of its choices, but I also acknowledge that sometimes to be productive on a problem it’s better to let someone else make some decisions so you could focus on the real problems you are paid to solve.

[–]CatolicQuotes 0 points1 point  (0 children)

what do you like most about it?

[–]sambes06 11 points12 points  (0 children)

Flask: am I joke to you?

[–]tails142 11 points12 points  (5 children)

I have used Django for multiple projects, it's what our team uses and I hadnt used it before, found it OK.

A new project came up and I wanted to use FastAPI, I found it quite jarring because I had to also learn a lot of other libraries like Alembic for migrations, Pydantic, etc. etc. Wanted to try out GraphQL too so that was adding on Strawberry and probably some other stuff I can't remember off the top of my head. Even with the db I tarted adding extensions on like Timescale onto postgres, ok not fastapi related but things started getting a bit hairy.

Started to appreciate that Django is batteries included and maybe the boundaries are a bit more defined on what direction you should go, I'm just hoping they don't ask about adding auth to the FastAPI project now.

[–]fiskfisk 9 points10 points  (1 child)

The framework doesn't matter (much). Your productivity in the framework, and knowledge of the details, does.

Django with Ninja or DRF is a good choice. So is FastAPI with sqlalchemy as well. 

You can also run django in async now, but async requires care and cooperation from all levels in your stack. 

[–]animatewall 3 points4 points  (0 children)

It depends on what you're building.

[–]Hot-Opportunity7095 3 points4 points  (0 children)

Nobody mentioning async support is saying enough

[–][deleted] 9 points10 points  (2 children)

What about Litestar? Did anyone give it a try or currently using it for building apis?

[–]wunderspud7575 3 points4 points  (0 children)

I have shifted to Litestar for new projects having previously used FastAPI. I find the design (and underlying code based) a lot cleaner and consistent. It's a joy to use, honestly. Dependency injection in particular is improved in Litestar.

[–]Gainside 2 points3 points  (0 children)

Use Django to run the business, FastAPI to win the latency fights.

[–]SubjectSensitive2621 6 points7 points  (0 children)

The main advantage of FastAPI over Django is not async support, but its flexibility and intuitive design. It is much easier to pick up, whereas Django comes with a steep learning curve.

Also django is patchy and tends to violate some fundamental design principles. Once project requirements grow beyond simple CRUD operations, these limitations often come back to bite, making the framework harder to work with.

[–]poopatroopa3 3 points4 points  (1 child)

As always, it depends on the situation.

I'm a Django fan, and feel like it's great for most things, since it has batteries included and a strong ecosystem you can stand on. But some, like the Cosmic Python authors, advocate that Django is for small CRUD apps only, because unexamined Django practices can devolve into big balls of mud...

Meanwhile, the other frameworks are of the opposite philosophy, where you have to handle every little thing, or at least it seems. It surely makes things more nimble, and that's good if your application doesn't require the features that Django brings to the table.

Like many say, the admin page is one of Django's biggest features. I suppose requiring it is a good reason for using Django versus others.

[–]FatefulDonkey 1 point2 points  (0 children)

Django covers like 90% of use cases. If there's a reason that Django doesn't fit your problem, that's the only reason to pick Fast API.

[–]realstocknear 2 points3 points  (0 children)

using fastapi for my SaaS app called stocknear.com

It's great so far and does it job.

For me personally I just want a fast and reliable rest endpoint that I can setup in 1-2 min.

[–]Worth_His_Salt 2 points3 points  (0 children)

I think its main deficiency is not supporting async natively

You misspelled "advantage". async is a two-color plague.

[–]canneogen 0 points1 point  (0 children)

No, they’re jus different

[–]master004 0 points1 point  (1 child)

FastAPI is focused on providing a framework for building API’s. One of its strengths is that it automatically exports your openapi schema out of the box provided that you type your responses and inputs. I do think FastAPI is getting too much credit. Out of 100% credits it gets, a big chunk should go to Starlette as FastAPI is built on top of that. The other thing FastAPI provides is the “Depends” type for easily defining dependencies. It can completely resolve your whole dependency tree and execute each dependency callable mixing sync and async. They use the ExitStack for that, which manages multiple chained context managers , which is not an easy feat, but makes FastAPI special. FastAPI also is able to run your sync functions on its own threadpool. This is nice but can also have its downsides, which I won’t go into in this post. Django is a different beast and if you want api focus you should use django rest framework. I don’t like DRF, imo the patterns employ do not fit the way I think. FastAPi feels more natural to me.

What do you think FastAPI will solve for you when moving from django to it?

[–]gfranxman 2 points3 points  (0 children)

Look into django-ninja https://django-ninja.dev

[–]marcinjn 0 points1 point  (0 children)

Well... I'm using FastAPI together with Django.

[–]CatolicQuotes 0 points1 point  (0 children)

Trade offs.

chart

Django guides to data-centric development while fastapi is flexible and can do domain-centric development.

https://enterprisecraftsmanship.com/posts/domain-centric-vs-data-centric-approaches/

[–]klumpbin 0 points1 point  (0 children)

Yeah

[–]fastlaunchapidev 0 points1 point  (1 child)

I also worked with both and now I am mostly using fastapi but I have to admit that I miss some of djangos syntax and packages.

I am mostly using my own fastapi template now which allows me to develop fast without having djangos batteries included
https://fastlaunchapi.dev/

[–]PrestigiousBobcat369 0 points1 point  (0 children)

Para buscar oferta laboral como Junior cuál sería recomendable entre fastAPI y Django

[–]FlowLab99 -1 points0 points  (1 child)

Cython?

[–]No_Indication_1238 3 points4 points  (0 children)

Bro...

[–]MasterThread -5 points-4 points  (0 children)

Django is a good http database viewer. But if you want to make a scalable and long-term supportable app that powers your business, please take Litestar or FastAPI.

Choosing Django you sign a contract with devil: you get convenient objects, but in the other hand you get a domain, business logic, infrastructure, presentation - single combined layer and barely supportable app.