Chapter 3. Data Modeling in Flask

This chapter covers one of the most important parts of any application, that is, the interaction with database systems. This chapter will take us through how Flask can connect to database systems, define models, and query the databases for retrieval and feeding of data.

In this chapter, we will cover the following recipes:

  • Creating a SQLAlchemy DB instance
  • Creating a basic product model
  • Creating a relational category model
  • Database migration using Alembic and Flask-Migrate
  • Model data indexing with Redis
  • Opting the NoSQL way with MongoDB

Introduction

Flask has been designed to be flexible enough to support any database. The simplest way would be to use the direct sqlite3 package, which is a DB-API 2.0 interface and does ...

Get Flask Framework Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.