Implementing async CRUD transactions using SQLAlchemy
From version 1.4, SQLAlchemy supports asynchronous I/O (AsyncIO) features, which enables support for asynchronous connections, sessions, transactions, and database drivers. Most of the procedures for creating the repository are the same as those for the synchronous setup. The only difference is the non-direct access that the CRUD commands have with the asynchronous Session
object. Our ch05b
project showcases the asynchronous side of SQLAlchemy.
Installing the asyncio-compliant database drivers
Before we begin setting up the database configuration, we need to install the following asyncio-compliant drivers: aiopg
and asyncpg
. First, we need to install aiopg
, a library that will assist with any asynchronous access to PostgreSQL:
pip install aiopg
Next, we must install asyncpg
, which helps build PostgreSQL asynchronous transactions through Python’s AsyncIO framework:
pip install asyncpg
This driver is a non...