27 ms·
I love Django, but I can’t help but feel FastAPI > Django these days.
by canadiantim 4y ago
I love Django, but I can’t help but feel FastAPI > Django these days.
- simonw 4y agoDoes Django's increasing levels of support for asyncio balance things back for you at all?
- tmpz22 4y agoNot GP but $work is DRF + React. For new projects async runtimes are enticing but its really hard to switch to or from a async runtime with an existing project. Similarly moving to or from the Django ORM or SQLAlchemy + Pydantic is too much work for most to justify. So whatever fully featured framework you start with will be the one you stick with. They all have warts and hurdles but should get you where you need to be from a business perspective.
- thewataccount 4y agoWe use django for our websites where I work, and I use it for personal projects for the ORM. How do you like the ORM for FastAPI? I've wanted to try it but since I already know how to use django it's been hard to find a reason to try FastAPI. Currently I _really_ like Django's orm.
- Zetice 4y agoYou end up missing Django's ORM when you can't use it, as well. I've tried my best to recreate the experience with Prisma in JS but it took me awhile to get to a place where I felt like I wasn't duplicating schema...
- barefeg 4y agoFastAPI doesn’t come with an ORM out of the box. There’s https://sqlmodel.tiangolo.com/ https://sqlmodel.tiangolo.com/ which wraps SQLAlchemy and allows defining the database models with pydantic-like classes. For me neither Django nor SQLAlcjemy hit the right spot when trying to define “pure” domain models that have no dependency (I.e. no ORM information). For that I created a repository pattern approach that converts “domain mode operations” into SQLModel query operations via filter specifications (https://martinfowler.com/apsupp/spec.pdf https://martinfowler.com/apsupp/spec.pdf). The result is that I always need to define 2 models: one is my pure domain model and another is a “table model” (defined in SQLAlchemy) along with a mapping between the two (for cases where there’s no 1-to-1 trivial mapping between their fields). Also making some of the SQLAlchemy magic (for example back propagating relational attributes) is messy. But if you want to produce some quick applications I think SQLModel+FastAPI works quite well. I don’t think is as mature as Django though.
- WD-42 4y agoThere is no official ORM for FastAPI. You have to pick one yourself. Probably the most common choice is Sqlalchemy, which is not nearly as nice to work with as Django's ORM, in my opinion. It's also annoying to wire up. For non-db backed projects (but let's be honest, how many projects don't use a DB) FastAPI is a great choice.
- Bedon292 4y agoOne of the apps I worked on ended up switching away from Django because of all the magic in the ORM slowing things down significantly for us. Same DB and API, just written in FastAPI was a 4x speedup. That was 2+ years ago though, so cannot say where things currently are. And now anything new I do is FastAPI, and only deal with Django for existing apps. Yes there are annoyances with not having that ORM, but worth it for what I have been working on at least.
- miketery 4y agoHow does FastAPI compare on the ORM and serialization front? I enjoy using djangorestframework and it’s been nice leverage for me, especially dealing with binary formats (eg keys).
- Nextgrid 4y agoAre there really many projects where the actual web framework is the bottleneck, as opposed to the DB?
- SCUSKU 4y agoA good compromise I have found is to use Django Ninja [1]. It is inspired by FastAPI, so it has a lot of the nice things like the automatically generated Swagger/OpenAPI docs, as well as having routers as decorators, and using python types for automatic serialization. While I think FastAPI is great in its first class async support, Django has the Django ORM, plus Django Admin, which for me have been indisposable. [1] - https://django-ninja.rest-framework.com/ https://django-ninja.rest-framework.com/
- dnadler 4y agoWow this is really cool. Will definitely be taking a close look at this tomorrow!
- 0cf8612b2e1e 4y agoIs FastAPI still a bus factor of one? Last time I looked a year or two ago, there were quite a few “easy” unresolved PRs that could have been handled with a bigger team. Django may be considered boring and old school, but it does so many things right that the barrier to switching is quite high.
- Danjoe4 4y agoDjango is so much more mature, which vastly better documention