r/FastAPI • • May 30 '21

Question question about fastapi and sqlalchemy

i am new to the SQLalchemy and fastapi libraries and i wonder if we can use sqlalchemy directly to connect to a database without the fastapi ? if no why ? i mean why would i add a third party in my connection to the database if i can read and put data using only sqlalchemy ?

reminder : i am new to working with apis and databases with python and i am working on a project with fastapi and sqlalchemy used

0 Upvotes

3 comments sorted by

11

u/SimonPreti May 30 '21

You can - SQLAlchemy and FastAPI is not inherently connected. FastAPI is made for creating APIs. SQLAlchemy is one ORM out of a bunch, that allows FastAPI to talk to your database.

-4

u/Square-Classroom-563 May 30 '21

yes i totally agree but why not use sqlalchemy to talk to the db directly ? or is it just for the interface and making things easier with fastapi

1

u/FairPassion21 May 31 '21

If your project is about web API then, you would need FastAPI rather than sqlalchemy. I create APIs and i prefer to not use ORM but native SQL with some added security. So i dont use sqlalchemy but i can use database.