Python SQLAlchemy Tutorial
A full tutorial series on Python’s SQLAlchemy library – The Database Toolkit for Python.
Introductory Tutorial of Python’s SQLAlchemy
Python’s SQLAlchemy and Object-Relational Mapping A common task when programming any web service is the construction of a solid database backend. In the past, programmers would write raw SQL statements, pass them to the database engine and parse the returned results as a normal array of records. Nowadays, programmers can write Object-relational mapping (ORM) programs […]
Read MoreHow to Install SQLAlchemy
In the previous article of the series Introductory Tutorial to Python’s SQLAlchemy, we learned how to write database code using SQLAlchemy’s declaratives. In this article, we are going to learn how to install SQLAlchemy on Linux, Mac OS X and Windows. Installing SQLAlchemy on Windows Before installing SQLAlchemy on Windows, you need to install Python […]
Read MorePython’s SQLAlchemy vs Other ORMs
Overview of Python ORMs As a wonderful language, Python has lots of ORM libraries besides SQLAlchemy. In this article, we are going to take a look at several popular alternative ORM libraries to better understand the big picture of the Python ORM landscape. By writing a script that reads and writes to a simple database […]
Read MoreOverview of SQLAlchemy’s Expression Language and ORM Queries
Overview In the previous article, we made a comparison between SQLAlchemy and other Python ORMs. In this article, we are going to take a deeper look at SQLAlchemy’s ORM and Expression Language and use an example to showcase their empowering API and easy-to-understand Python structures. Not only does the SQLAlchemy ORM provide a way to […]
Read MoreSQLAlchemy – Some Commonly Asked Questions
Common Questions Before we dive deeper into SQLAlchemy, let’s answer a possible list of questions regarding the ORM: Can you prevent SQLAlchemy from automatically creating a schema? Instead, can you bind SQLAlchemy models to an existing schema? Is there a performance overhead when using SQLAlchemy, compared to writing raw SQL? If so, how much? If […]
Read MoreSQLAlchemy ORM Examples
ORM Recap In one of the previous articles, we briefly went through an example database with two tables department and employee where one department can have multiple employees and one employee can belong to arbitrary number of departments. We used several code snippets to demonstrate the power of SQLAlchemy’s expression language and show how to […]
Read MoreSQLAlchemy Association Tables
Association Tables In our previous articles, we used an association table to model many-to-many relationships between tables, such as the relationship between Department and Employee. In this article, we are going to dive deeper into the association table concept and see how we can use it to further solve more complicated problems. DepartmentEmployeeLink and Extra […]
Read MoreUnderstanding Python SQLAlchemy’s Session
What are SQLAlchemy Sessions? What does the Session do? One of the core concepts in SQLAlchemy is the Session. A Session establishes and maintains all conversations between your program and the databases. It represents an intermediary zone for all the Python model objects you have loaded in it. It is one of the entry points […]
Read MoreSQLAlchemy Expression Language, Advanced Usage
Expression Language One of the core components of SQLAlchemy is the Expression Language. It is allows the programmer to specify SQL statements in Python constructs and use the constructs directly in more complex queries. Since the expression language is backend-neutral and comprehensively covers every aspect of raw SQL, it is closer to raw SQL than […]
Read MoreSQLAlchemy Expression Language, More Advanced Usage
Overview In the previous article SQLAlchemy Expression Language, Advanced Usage, we learned the power of SQLAlchemy’s expression language through a three table database including User, ShoppingCart, and Product. In this article, we are going to review the concept of materialised path in SQLAlchemy and use it to implement product containing relationships, where certain products may […]
Read More