Skip to content

Tutorial - User Guide

In this tutorial you will learn how to use SQLModel.

Type hints

If you need a refresher about how to use Python type hints (type annotations), check FastAPI's Python types intro.

You can also check the mypy cheat sheet.

SQLModel uses type annotations for everything, this way you can use a familiar Python syntax and get all the editor support possible, with autocompletion and in-editor error checking.

Intro

This tutorial shows you how to use SQLModel with all its features, step by step.

Each section gradually builds on the previous ones, but it's structured to separate topics, so that you can go directly to any specific one to solve your specific needs.

It is also built to work as a future reference.

So you can come back and see exactly what you need.

Run the code

All the code blocks can be copied and used directly (they are tested Python files).

It is HIGHLY encouraged that you write or copy the code, edit it, and run it locally.

Using it in your editor is what really shows you the benefits of SQLModel, seeing how much code it saves you, and all the editor support you get, with autocompletion and in-editor error checks, preventing lots of bugs.

Running the examples is what will really help you understand what is going on.

You can learn a lot more by running some examples and playing around with them than by reading all the docs here.