flâneur — a map of the web's best reading

SQL (Relational) Databases - FastAPI

fastapi.tiangolo.com · 20,967 words · saved by 1 readers

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 (

Explore this link on the map →

related reading