Improving the TODO app with SQLAlchemy¶
Who is this tutorial for?
This tutorial is aimed at developers who are already familiar with Litestar’s core concepts such as route handlers and dependency injection.
If you are new to Litestar, it is recommended to first follow the Developing a basic TODO application tutorial.
Install SQLAlchemy via Advanced Alchemy¶
To follow this tutorial, you will need Advanced Alchemy installed. You can install it with pip install advanced-alchemy[aiosqlite]', or let
Litestar install it for you by installing the sqlalchemy extra (e.g., pip install 'litestar[standard,sqlalchemy]' aiosqlite).
Note
SQLAlchemy support in Litestar is now provided by Advanced Alchemy,
a first-party library. All imports should use advanced_alchemy.extensions.litestar instead of the deprecated
litestar.contrib.sqlalchemy or litestar.plugins.sqlalchemy modules.
What’s in this tutorial?¶
This tutorial builds on the TODO app tutorial by adding a database backend using SQLAlchemy via Advanced Alchemy.
We start by comparing a refactored TODO app that leverages SQLAlchemy for data persistence to the TODO app from the TODO app tutorial.
We will then gradually improve on the design of our app by utilising more of Litestar’s features, such as dependency injection, and plugins.