Overview

Alchemy came onto the scene during antiquity or some time long ago with promises of turning common metals like lead into ‘noble metals’ like gold. With a mix of spirituality and pseudo-science alchemy became a labor of love, for many. Though this article has nothing to do with actual alchemy, there are redeemable qualities in this transformative pursuit. We will use this as motivation when describing the power of SQL Alchemy and its ability to turn ‘common’ python code into ‘noble’ sql queries.

The Catalyst

Like most concoctions there must be a catalyst, in this case we will use the Python library SQL Alchemy to drive the interaction between our python script and our SQLite database. Here are the necessary imports,

import sqlalchemy as db
from sqlalchemy import create_engine

From here we have to establish a connection. For the following examples we are going to be connecting to and querying from a database that contains information about a fictional movie rental store.

#sql #sqlalchemy #database

Querying an SQL Database with SQL Alchemy
2.15 GEEK