Using SQLAlchemy with Flask and PostgreSQL

python_tutorials

Introduction

Databases are a crucial part of modern applications since they store the data used to power them. Generally, we use the Structured Query Language (SQL) to perform queries on the database and manipulate the data inside of it. Though initially done via dedicated SQL tools, we’ve quickly moved to using SQL from within applications to perform queries.

Naturally, as time passed, Object Relational Mappers (ORMs) came to be – which enable us to safely, easily and conveniently connect to our database programmatically without needing to actually run queries to manipulate the data.

One such ORM is SQLAlchemy. In this post, we will delve deeper into ORMs and specifically SQLAlchemy, then use it to build a database-driven web application using the Flask framework.

What is an ORM and why use it?

Object-relational mapping, as the name suggests, maps objects to relational entities. In object-oriented programming languages, objects aren’t that different from relational entities – they have certain fields/attributes that can be mapped interchangeably.

That being said, as it’s fairly easy to map an object to a database, the reverse is also very simple. This eases

To finish reading, please visit source site