Python applications often store their data in relational databases. When you write the SQL yourself, you also have to turn rows into objects, link related records, and protect queries against SQL injection. Each schema change then means finding and updating the affected queries by hand.
An Object Relational Mapper (ORM) takes much of this work off your hands by mapping Python classes to database tables. A class describes a table, an object stands for a row, and an attribute holds a column value. SQLAlchemy , a widely used Python database library, includes an ORM that writes the SQL for you and still lets you inspect it.
In this tutorial, you'll build a small library database with SQLAlchemy ORM. You'll define models, add and query records, load related data efficiently, and handle failed transactions.…