SQL, Mappers, and ORMs: Database Abstractions in Python
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-05-13 23:31:28 +02:00
sql aiosql section 2026-05-11 13:46:00 -07:00
src/absdemo Readme and welcome message 2026-05-12 16:57:42 -07:00
.gitignore aiosql section 2026-05-11 13:46:00 -07:00
.python-version aiosql section 2026-05-11 13:46:00 -07:00
pyproject.toml aiosql section 2026-05-11 13:46:00 -07:00
README.md Remove reference to requirements file 2026-05-13 23:31:28 +02:00
uv.lock aiosql section 2026-05-11 13:46:00 -07:00

Pycon US Tutorial 2026

SQL, Mappers, and ORMs: Database Abstractions in Python

Abstract

Getting your Python code talking to a database requires an interface that links your code to bona fide database interactions.

In Python, low-level abstractions allow for SQL strings to be passed through database drivers, enabling database operations. At the highest end, there are Object Relational Mappers (ORMs), converting raw SQL operations into more Pythonic abstractions. There are also tools that exist in between, allowing for query mapping/organizing, while retaining certain advantages, like type safety and parameter/object handling.

Learn the differences between these tools and what some of their strengths and limitations might be in your particular workflows.

From the lowest level, we will work with aiosql, which allows you to write your database code in .sql files and load the SQL strings into your code.

On the highest level, we will look at Advanced Alchemy, a powerful companion library for SQLAlchemy, and see how it compares to Django's ORM.

We'll also look at some tools that fall somewhere in between. One of these is DBXS, a query organizer harnessing the power of Python's Protocol class to build database interfaces using a repository pattern. Lastly, we'll look at sqlspec, a type-safe query mapper designed for minimal abstraction between Python and SQL.

Getting Started

Create a directory for your project:

mkdir tutorial-project
cd tutorial-project

Clone the repository:

git clone https://codeberg.org/pythonbynight/pycon-tutorial-2026.git

If you have uv installed, install the dependencies like this:

uv sync

If you don't have uv installed you can use pip instead:

# Create a virtual environment
python -m venv .venv

# On Linux/MacOS
source .venv/bin/activate

# Or Windows
.venv/Scripts/activate

# First, upgrade pip
python -m pip install --upgrade pip

# Then install dependencies
python -m pip install .

And now test to make sure CLI app is running. Make sure that your virtual environment is activated.

# Invoke the demo app with the following command
absdemo

Lessons

This tutorial is divided into four sections.

Lesson 1: 1-aiosql Lesson 2: 2-sqlspec Lesson 3: 3-dbxs Lesson 4: 4-advanced-alchemy

To switch to a new lesson, switch to the appropriate branch.

# For example
git switch 1-aiosql