If you’re learning Python and want to level up your understanding of databases without diving deep into raw SQL, then this post is for you! In this blog, I’ll walk you through the concept of Python ORM (Object-Relational Mapping) using SQLAlchemy, and I’ll also share a hands-on project that we built step-by-step in the video below.
Video included at the end of this post — be sure to check it out for a complete beginner-friendly walkthrough!
What is Python ORM?
ORM stands for Object-Relational Mapping. It’s a powerful programming technique that allows you to interact with your database using regular Python classes and objects, instead of writing SQL queries manually.
Here’s a simple way to think about it:
- Database tables are represented as Python classes
- Table rows become Python objects
- Columns become class attributes
- And instead of using SQL statements like
SELECT
orINSERT
, you use Python methods like.add()
,.filter()
, or.commit()
ORM helps you write cleaner, more readable, and maintainable code—especially useful as your project grows or if you’re not too comfortable writing raw SQL.
What You’ll Learn in the Video
In the video tutorial, we cover both the concept and the practical application of ORM using SQLAlchemy. Here’s what to expect:
- An explanation of ORM vs SQL
- What a one-to-many relationship looks like in a real database
- What a foreign key is and how it connects two tables
- How to build a mini inventory system with suppliers and products
- How to structure your project into separate, modular Python files
- How to:
- Create a SQLite database
- Define models using Python classes
- Insert records (suppliers and products)
- Query and display related data
- Filter records
- Update and delete data
- A step-by-step demo using
main.py
to test every interaction - How to open and inspect your database directly in PyCharm
Get the Code on GitHub
All of the code used in the video is available in my public GitHub repository. You can download it, explore each file, and follow along at your own pace.
Click here to view the GitHub repo
The repo includes:
- Well-structured Python files (
database.py
,models.py
,create_tables.py
, etc.) - A sample dataset
- A ready-to-run
main.py
to test everything in sequence
Watch the full video to follow along and build the project with me. It’s perfect for beginners and those who want a clear understanding of ORM outside of Django.
If you enjoy this kind of tutorial, don’t forget to like the video and subscribe to my channel—it helps a lot!