FastAPI is good but it is something I wouldn't go for
Posted by donalddbanda@reddit | Python | View on Reddit | 27 comments
I wanted to learn web development using Python so I started learning Flask instead of Django because Flask gives a developer more freedom of tools when compared to Django. I'm have a better experience with Flask. I wanted to learn FastAPI because of its asynchronous nature.
FastAPI is hard for me to create a database, and connect it. It needs many imports which is something I don't like
Pydantic makes it hard to pick up the framework. The use of many classes makes it complicated.
Is it only me or it happens to many developers learning FastAPI??
miabajic@reddit
If you’ve worked with Flask, maybe try rewriting it in FastAPI. If you’re already using SQLAlchemy, you can use it with FastAPI too, so basically the only real difference is mainly Pydantic and some FastAPI-specific stuff. When I first used it, I also found it a bit complicated, but you'll pick it up quickly and Pydantic is super useful in real-world projects.
Difficult_Run_8800@reddit
FastAPI is really great for learning. It gives you the opportunity to make a lot of mistakes and that's fine.
We learn faster with mistakes and by solving problems.
I may not know you and your previous experience with web development, but I hope that you will continue to use FastAPI to learn.
donalddbanda@reddit (OP)
still learning i din't stop
binaryfireball@reddit
"FastAPI is hard for me to create a database, and connect it"
donalddbanda@reddit (OP)
This makes sense. It needs more learning
libsaway@reddit
Not sure I understand this, why is FastAPI hard to connect a database to?
moric7@reddit
But flask has no websockets?
donalddbanda@reddit (OP)
You're right, Flask doesn't have built-in support for web sockets but if you're comfortable enough working with Flask, you can use libraries like Flask-SocketIO for WebSocket support.
Miserable_Ear3789@reddit
Shameless plug incoming: If your looking to learn ASGI and maintain maximum freedom you can try my ultra micro ASGI framework MicroPie. Inspired by CherryPy but async.
nicwolff@reddit
Try Quart (or Starlette) + SQLAlchemy Core.
moric7@reddit
For simple tasks, you can try Cherrypy
Zer0designs@reddit
Pydantic in itself is worth learning.
donalddbanda@reddit (OP)
Real
MMetalRain@reddit
You could use just Starlette instead of FastAPI.
donalddbanda@reddit (OP)
I'll check it out
Natural-Intelligence@reddit
I think you have gotten confused about the tooling:
Pydantic is a data validation library. It does not care what other frameworks you use. With FastAPI, you should use it for user input validation and for the dependency system but other usage is up to you
FastAPI is not a database. Similarly with Flask, you need to configure the database yourself. Neither will include a database out-of-the-box.
If you don't like imports, you should study more about how to structure Python projects. Or then the issue is that your IDE can't lint and you should change to more modern software development tooling (ie. VS Code or Pycharm). Hating imports is like hating modular code.
donalddbanda@reddit (OP)
This is real
LoudSlip@reddit
Fastapi and sqlmodel, is absolutely goated. If your struggling with your database side of things with fastapi (i dont know how you do any db stuff with fastapi) but sqlmodel is what you need for db, its one of the most innovative and nice to use sql connectors and its built to work with fastapi intuitively
donalddbanda@reddit (OP)
I'll try this
ara-kananta@reddit
Try Litestar
donalddbanda@reddit (OP)
Is this a Python package?
ara-kananta@reddit
Its a web framework not as sketelon as fastapi but not as batteries included like django i have been using it for months
Also get used to use pydantic(or other similiars) its really popular
TheDeadlyPretzel@reddit
So... Not to look down on you, we all had a learning path, but it sounds to me like you want control (which is very good I love to see that trait in developers) but still have to learn that control also usually means more moving gears, more loose components, getting less out of the box...
Stick with it, learn those loose components, that is how you become truly good! If you can only work with a DB in Django, you don't actually know how to work with a DB anywhere else.
This is why it is a good thing that FastAPI doesn't give all that for free.
Pydantic is so useful, it can be used anywhere For DBs, I love using SQLalchemy, but you can use anything you like. Point is once you learn SQLalchemy, or whatever standalone lib you wanna use, you can use it in FastAPI, a CLI application, a Tkinter GUI, it doesn't matter...
So yeah, once you master these loose components, you'll come back to this post and laugh at your own ignorance (again I mean this in the best possible way, we were all like that once!)
donalddbanda@reddit (OP)
This is motivation
TheDeadlyPretzel@reddit
You got this!
Mleba@reddit
What do you mean connect to a database? Fastapi is for a web backend, use something else for the database connection.
donalddbanda@reddit (OP)
Okay