The Nerd Nook

The Nerd Nook

3 Randoms

SQLModel Explained: The Easiest Way to Use Databases in Python

Learn SQLModel step by step and see how to build Python database models, run queries, and validate data using one clean, modern ORM built for real apps.

Josh Wenner's avatar
Josh Wenner
Dec 17, 2025
∙ Paid

Working with databases should not feel like you have to choose between clean Python code and real SQL power, and that is where SQLModel fits in.

SQLModel is a modern Python library built by the same person who created FastAPI, and it sits right between SQLAlchemy and Pydantic.

If you have ever thought that SQLAlchemy feels a bit heavy, or that Pydantic is great but does not actually talk to a database, SQLModel was made to solve that exact problem.

You define a class once and that class becomes your database table, your Python object, and your validation model all at the same time. There is no duplication and no separate files that slowly drift out of sync.

You describe your data once and then use it everywhere, whether you are saving to a database, validating input, or passing data around your app.

Welcome to SQLModel. Check out other 3 Random Articles here.

Imagine you’re subscribed to a newsletter called 3 Randoms. Each week, it introduces you to three lesser-known Python tools that can make your coding better. It’s like expanding your toolbox and discovering new tricks.

What really sold me on it is how natural it feels to write. You use normal Python type hints, and suddenly those hints actually matter. They turn into database columns, they validate data, and they make your editor more helpful.

If you already use FastAPI, SQLModel feels like it was always meant to be there. If you come from SQLAlchemy, it feels familiar but simpler. If you come from writing raw SQL, it gives you structure without hiding what is really going on.

In this article, we are diving into SQLModel and three practical pieces of it that you can use right away. You will see how models, sessions, and queries work together in a way that feels practical and grounded, not theoretical.

These examples are not meant to cover everything. They are meant to give you a solid base so the next time you need to store, query, or validate data in Python, SQLModel feels like an easy choice.

Thank you guys for allowing me to continue to do work that I find meaningful. This is my full time job so I hope you will support my work. You can now subscribe on the substack app!

My premium readers get access to so much more, like monthly Python projects, in-depth weekly articles, this here ‘3 Randoms’ series, and my complete archive!

👉 If you get value from my work, please leave it a ❤️ and share it. This helps more people discover this newsletter, which helps me out immensely!

This Week’s SQLModel Tips

Keep reading with a 7-day free trial

Subscribe to The Nerd Nook to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 The Nerd Nook · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture