SQL (Relational) Databases - FastAPI
The new docs will include Pydantic v2 and will use SQLModel (which is also based on SQLAlchemy) once it is updated to use Pydantic v2 as well. FastAPI doesn't require you to use a SQL (relational) database. But you can use any relational database that you want. Here we'll see an example using SQLAlchemy. You can easily adapt it to any database supported by SQLAlchemy, like: In this example, we'll use SQLite, because it uses a single file and Python has integrated support. So, you can copy this example and run it as is. Later, for your production application, you might want to use a database server like PostgreSQL. Tip There is an official project generator with FastAPI and PostgreSQL, all based on Docker, including a frontend and more tools: https://github.com/tiangolo/full-stack-fastapi-postgresql Note Notice that most of the code is the standard SQLAlchemy code you would use with any framework. The FastAPI specific code is as small as always. FastAPI works with any database and any s
SQL (Relational) Databases ¶ FastAPI doesn't require you to use a SQL (relational) database. But you can use any database that you want. Here we'll see an example using SQLModel . SQLModel is built on top of SQLAlchemy and Pydantic. It was made by the same author of FastAPI to be the perfect match for FastAPI applications that need to use SQL databases . Tip You could use any other SQL or NoSQL database library you want (in some cases called "ORMs" ), FastAPI doesn't force you to use anything. 😎 As SQLModel is based on SQLAlchemy, you can easily use any database supported by SQLAlchemy (
related reading
- Building data-centric apps with a reactive relational databaseriffle.systems
- Python: Just write SQLjoaodlf.com
- SQLAlchemy in Flask | G-Testerhuohuoren4.github.io
- SQLAlchemysqlalchemy.org
- Here is the reason why SQLAlchemy is so popular. | Towards Data Sciencetowardsdatascience.com
- Bigger Applications - Multiple Files - FastAPIfastapi.tiangolo.com
- Mediumpython.plainenglish.io
- SQLAlchemy - Quick Guidetutorialspoint.com
- Against SQLscattered-thoughts.net
- SQL vs NoSQL in 8 Examples | Towards Data Sciencetowardsdatascience.com
- Wesley Aptekar-Cassels | Consider SQLiteblog.wesleyac.com
- How Does a Database Work?cstack.github.io