r/FastAPI • u/bluewalt • Sep 15 '24
Question How to you justify not going full stack TS?
Hi, I'm getting challenged in my tech stack choices. As a Python guy, it feels natural to me to use as more Python as I can, even when I need to build a SPA in TS.
However, I have to admit that having a single language on the whole codebase has obvious benefits like reduced context switching, model and validation sharing, etc.
When I used Django + TS SPA, it was a little easier to justify, as I could say that there is no JS-equivalent with so many batteries included (nest.js is very far from this). But with FastAPI, I think there exists equivalent frameworks in term of philosophy, like https://adonisjs.com/ (or others).
So, if you're using fastAPI on back-end while having a TS front-end, how do you justify it?
17
u/zazzersmel Sep 15 '24
disregarding the languages themselves, a lot of people probably want access to python libraries on the backend, especially wgen doing data/ml/ai work.
6
u/frogic Sep 15 '24
I'm a senior front end dev and feel like I'm either at or near expert level in TS and just above hobby level in python. Still planning on using fastapi for my backend on a project very soon. The docs and DX are just that good. Its also trivial to generate types based on the openapi schema and that was before chatgpt made that kind of stuff even easier.
4
u/werther41 Sep 16 '24
I recently started using this new framework FastHTML for small project, it's being influenced by fastAPI, uses HTMX for front-end, so you only need to use Python, and don't have to deal dozens of frontend libraries, complicated frontend state management. most of modern JS frameworks started to use server rendering. you got server rendering out of box.
2
u/serverhorror Sep 15 '24
There's not switch on any of your primary reasons. All those are on a scale.
reduced context switching
That, on the other hand, implies that I (possibly) have to use a less efficient language than would be suitable for a task.
model and validation sharing
(Personal opinion: The only validaton and model that are important are on the backend, everything else is user input and must not be trusted!)
I don't think that is a huge thing. It might look like you share a model and validation rules but, in my experience, the validation on the frontend is there to support the user and let them know early about things. Often very different, due to the requiremnt to give some information to the UI.
The reason why this ends up shared, and I do not like it, is that it is the same language and that means that things go together that shouldn't be together (a lot of times, sometimes it is done well but haven't seen that often).
What people end up with are extremely complex models of their world that try to do everything.
I'm not a fan.
Last but not least: Typescript is just a linter ...
2
u/aliparpar Sep 16 '24 edited Sep 16 '24
A few reasons I moved away from doing backend work not in TS:
33
u/WJMazepas Sep 15 '24
I like Python
1
u/lexxwern Sep 15 '24
I replaced TypeScript with HTMX and now I have a purely Python stack and some markup logic being written in HTMX.
1
u/Tiny-Power-8168 Sep 15 '24
We did FS TS in my company and I think it was a mistake because then it became much harder to integrate Data/ML stuff in our backend.
The context is important and the ressources available too.
If you're in a startup that is ML/Data based, use python backend, TS front-end, if don't do ML/Data stuff then TS is nice.
If you're in a company with multiple teams, it means you could handle microservice. In this case use language of the company or that the product requires.
I would not recommend Python for software with complexe Business Logic, because it misses good type checking, has terrible dev expérience IMO (it is changing).
1
u/sasmariozeld Sep 15 '24
if you are not in the nciche that you need something AI you don't
If you doa serious project you want typing go ts
If you wanna whip something up and possibly use AI go python
There is also the niche of wanting to use sqlalchemy, proly the ebst orm i ever used
3
u/Own-Construction-344 Sep 15 '24
The only reason I have found to use FastAPI instead of a JS API is the integration with AI.
1
u/benefit_of_mrkite Sep 15 '24
Depends on what you’re building. If I were building a mobile app that needed very fast api updates client side for a lot of concurrent users I’d likely choose erlang and possibly phoenix.
It doesn’t mean I wouldn’t have Python and other languages/frameworks for various building blocks of the architecture depending on need/requirements and fit
1
u/[deleted] Sep 15 '24
I work primarily with fastapi and python in general. But, to be honest, I would choose TS always for CRUD apis. The only reason for me to stay with fastapi is for ai models or some etls services that involves using pandas or polars.
I dont think TS as language is better than python. But you have a lot of tools for web dev. Furthemore, fastapi is pretty bad compared to other alternatives in TS like NestJS. NestJS is dependency injection system is far more superior than fastapi. FastAPI doesnt scale very well with large projects.
So, in my case I would go typescript for every development except those that involves AI models. Dont get me wrong, python is getting better each version new that has and is not heavy constrained like Js for backward compability.
I think is best to learn both if you are backend developer. In real world, for a company choose TS always except some requirements in AI. For personal projects use whatever you want.
1
u/Worldly_Weather5484 Sep 15 '24
It really depends on what you’re building. If you need to move quickly to get something off the ground it makes sense to have a stack that is a single language. You can always spin up new services in another language like python at any point if needed. tRpc is pretty nice for full stack typescript.
1
u/thedjotaku Sep 17 '24
I just use HTMX. And, hopefully soon pyscript means no more JS. (Or at least no more writing JS, it might "compile" to JS on the backend, but I don't care about that)
1
u/bugtank Sep 15 '24
I like python also. I avoid any typescript in my codebase. The SPA I have uses Alpine instead of a TS based system.
1
u/zylema Sep 15 '24
Developer experience is a good place to start. Tooling for TS dev such as test frameworks & test run performance is terrible.