Over the summer, I learned that Python is at the top of the IEEE programming languages ranking. It is also my favorite language for quickly coding tools, web apps and analyzing data with notebooks (such as on IBM Data Science Experience). Did you know that IBM provides four different Db2 drivers for Python? These are:
A driver with the native Db2 API.
A driver that supports the official Python DBI (database interface).
A driver for the popular SQLAlchemy Python SQL Toolkit.
A driver for the Python-based Django web framework.
In an older article, I showed you how to use SQLAlchemy with Db2. Today, I am going to demonstrate you how simple it is to create a SQL database-backed web app in the IBM Cloud, utilizing the native Db2 API.
The app is based on the Flask web framework and provides access to city information. The data comes from GeoNames. After the data has been loaded into Db2, it is accessed by the app and displayed using a simple page template. Users can search via a form or directly access city information through static URIs.
I put the source code and all required instructions into a GitHub repository. The included README takes you through all the steps from provisioning a Db2 database on the IBM Cloud to creating a table and loading data to how to deploy the app. Make sure to take a look at the (few!) comments in the files that provide additional insight.
You can find an extended version of the instructions as a tutorial in the docs for IBM Cloud.