Setting up SQLAlchemy
In order to follow along in this chapter, you will need a running database if you do not already have one. If you have never installed a database or you do not have a preference, SQLite is the best option for beginners.
SQLite is a SQL that is fast, works without a server, and is entirely contained in one file. Also, SQLite is natively supported in python. If you choose to go with SQLite, a SQLite database will be created for you in the Our first model section.
Python packages
To install Flask SQLAlchemy with pip
, run the following:
$ pip install flask-sqlalchemy
We will also need to install specific packages for the database you chose to use that will act as the connector for SQLAlchemy. SQLite users can skip this step:
# MySQL $ pip install PyMySQL # Postgres $ pip install psycopg2 # MSSQL $ pip install pyodbc # Oracle $ pip install cx_Oracle
Flask SQLAlchemy
Before we can abstract our data, we need to set up Flask SQLAlchemy. SQLAlchemy creates its database connection...