4 ms·
I’m tempted to go FastAPI over Django on my next project, even though I’ve been a big Django user. A little more performance and a little less coupling, and may
by travisjungroth 6y ago
I’m tempted to go FastAPI over Django on my next project, even though I’ve been a big Django user. A little more performance and a little less coupling, and maybe you can survive longer as a Python monolith. Then convert to Rust/Go/something in the unlikely event of wild success.
- maxs 6y agoWhy do you think it reduces coupling? You can use Django apps to have decoupled Django services that all run in the same gunicorn webserver
- travisjungroth 6y agoI mean less logical coupling inside the app. It's more in the family of a collection of libraries versus a batteries included framework. I'm considering that may be the best of both worlds. I never really liked the recreating the universe feeling of Flask.
- Daishiman 6y agoWhy? The FastAPI library ecosystem is anemic. Django is fast enough. You'll be spending at most a fraction of an FTE salary in hosting even with the best of success, and if it comes to more than that, you'll be likely paying for a DBA or for an improved caching strategy for performance.
- travisjungroth 6y ago> The FastAPI library ecosystem is anemic. That's kinda the point. If your business is making webapps for clients, the fact that you can pip install django-half-the-feature is awesome. What you trade for that is a big dependency tree whose packages sometimes snake their way through your whole codebase, since it's all Django anyway. FastAPI is its own thing, but it's also heavily based on some other big libraries that also have their own support. And anyway, what I was saying about performance and decoupling are probably just rationalizations. I focus on writing APIs, and that looks nicer to do in FastAPI than how I've done it in Django. I also really like type hinting, and that's a big part of things. Right now, I'd just like to write more Python and less Django.
- ryanisnan 6y agoThe biggest challenge I encountered when doing this exact thing was once you get beyond bootstrapping the project, and start implementing your first feature. Great, you need an ORM, what do you choose? Now you need a serializer, what do you choose? What about validation, what do you choose? Authentication, what do you choose? A lot of these questions are boring and are not worth spending time thinking about. Almost all choices will leave you with some amount of headaches though (as will choosing Django). The question to me boils down to... what questions am I interested in solving?
- travisjungroth 6y agoBy "doing this exact thing" do you mean making an API with FastAPI? Because you seem unfamiliar with its features. > Great, you need an ORM, what do you choose? SQLAlchemy. It's very popular. > Now you need a serializer, what do you choose? Pydantic, which is included. (Django doesn't include serializers). > What about validation, what do you choose? Pydantic. > Authentication, what do you choose? The included auth library.
- ryanisnan 6y agoIn a couple of attempts, I have worked with Flask and Falcon. My point isn't that there are solutions, my point is that you have to make decisions, all of which are likely to have rough edges.
- travisjungroth 6y agoAnd my point is that for your specific examples, you don't have to make decisions. Django and FastAPI both have 3/4 of the features you listed included. FastAPI is a tool made for making APIs. Django is not. So in that specific case, Django actually requires more decisions overall.
- Daishiman 6y agoDjango Rest Framework is the one-stop shop for APIs. Probably the most deployed API framework ever.
- bliteben 6y agoYou might want to check out https://github.com/vitalik/django-ninja https://github.com/vitalik/django-ninja. I much prefer it over restframework.
- andybak 6y agoWow. vitalik was one of the first Django freelancers I hired when I was getting started. Some of his code is still in production for one of my clients. (Vitaly - if you're watching. Hi!)
- avinassh 6y agointeresting, the benchmarks include Flask which is a non-async framework, but not FastAPI
- travisjungroth 6y agoThanks! That seems very well suited for my stated goals. (Which after conversation here I realized weren’t exactly my real goals :P)
- avinassh 6y agoWhat makes the FastAPI to be fast that other frameworks? Is it cos of async? There is Tornado too, I am curious how do these fair against each other in terms of performance and productivity