A number of important Python modules must be in place to ensure that the Flask application and its connection to the PostgreSQL and PostGIS database components, will run as required. These modules will be downloaded and installed using pip, which connects to the Python Package Index (PyPI), an online repository of registered modules located at https://pypi.python.org/pypi.
These modules include:
- Flask, a pure Python MVC web framework (http://flask.pocoo.org/).
- Flask-SQLAlchemy, a database ORM module that can connect to a multitude of database backends (http://flask-sqlalchemy.pocoo.org/2.3/). This module installs SQLAlchemy.
- GeoAlchemy2, a Python module that builds on the SQLAlchemy module and the Postgres/PostGIS backend (covered in Chapter 7, Geoprocessing with Geodatabases), is used to allow for geospatial data columns and ORM spatial queries (https://geoalchemy-2.readthedocs.io/en/latest/).
- Flask-WTForms, a web form module built on the WTForms (https://wtforms.readthedocs.io/en/latest/) that allows for Flask to carry the logic of each web page and to process the inputs (https://flask-wtf.readthedocs.io/en/stable/).
- SQLAlchemy-Utils, used to manage database creation and deletion (https://github.com/kvesteri/sqlalchemy-utils/).
- psycopg2, used to create connections to the PostgreSQL database and is used by the SQLAlchemy module (http://initd.org/psycopg/).
- pyshapefile (or pyshp), used to read the shapefiles used in this example and add it to the database tables (https://pypi.python.org/pypi/pyshp).
- Finally, pygeoif (https://pypi.python.org/pypi/pygeoif) is used to allow for the conversion of data from a shapefile binary encoding to a well-known text (WKT) encoding, for insertion of geometry data into the database.
Other important supporting modules are automatically installed along with Flask and the preceding modules, including the Jinja2 templating system (http://jinja.pocoo.org/) and the Werkzeug Web Server Gateway Interface (WSGI) module (http://werkzeug.pocoo.org/).