Welcome to SQLAlchemy Tutorials
SQLAlchemy is presented as two distinct APIs: Core and ORM. These tutorials will guide you through both approaches, helping you become proficient with Python’s most powerful database toolkit.About SQLAlchemy
SQLAlchemy provides two primary ways to work with databases:SQLAlchemy Core
The foundational architecture providing database connectivity, query execution, and programmatic SQL construction.
SQLAlchemy ORM
Builds on Core to provide object-relational mapping, allowing Python classes to be mapped to database tables.
Learning Path
Follow these tutorials in sequence for the best learning experience:Unified Tutorial
Start with the Unified Tutorial to understand both Core and ORM fundamentals in an integrated way.
Data Manipulation
Learn how to insert, update, and delete data using the ORM.
Querying Data
Master querying with select(), filter(), and joins to retrieve exactly the data you need.
Working with Relationships
Understand relationship patterns and loading strategies for complex data models.
Tutorial Structure
Core vs ORM
Throughout these tutorials, you’ll learn:- Core-focused sections: Work directly with SQL constructs, tables, and connections
- ORM-focused sections: Use Python classes and sessions for object persistence
- Integrated sections: See how Core and ORM work together in SQLAlchemy 2.0
SQLAlchemy 2.0 features deep integration between Core and ORM. The ORM now uses Core-style querying with the
select() construct, making the APIs more unified than ever.What You’ll Learn
By the end of these tutorials, you’ll be able to:Define Models
Create declarative ORM models with typed attributes using
Mapped and mapped_columnExecute Queries
Build complex SELECT queries with filtering, ordering, joining, and grouping
Manage Relationships
Configure one-to-many, many-to-one, and many-to-many relationships with proper loading strategies
Handle Transactions
Work with sessions, transactions, and understand the Unit of Work pattern
Prerequisites
Before starting, you should have:- Basic Python knowledge (classes, functions, type hints)
- Understanding of relational database concepts (tables, rows, foreign keys)
- Python 3.7+ installed
- SQLAlchemy installed:
pip install sqlalchemy
Code Examples
All examples in these tutorials are:- Runnable: Copy and execute them directly
- Complete: No missing imports or setup code
- Modern: Follow SQLAlchemy 2.0+ best practices
- Typed: Use Python type hints for better IDE support
Getting Help
If you get stuck:- Check the code examples carefully - they include all necessary imports
- Review the notes and warnings in each section
- Consult the SQLAlchemy documentation for detailed API references
- Join the SQLAlchemy community on GitHub Discussions
Next Steps
Ready to begin? Start with the Unified Tutorial to learn the fundamentals of SQLAlchemy Core and ORM together.Start Learning
Begin with the SQLAlchemy Unified Tutorial