Wednesday, October 25, 2017

Use Db2 as Cloud SQL Database with Python

Load Data into IBM Db2 on Cloud
Over the Summer I learned that Python is top in the IEEE programming languages ranking. It is also my favorite language for quickly coding tools, web apps and analyzing data with notebooks (e.g., on IBM Data Science Experience). Did you know that IBM provides four (4) different Db2 drivers for Python? There is a driver with the native Db2 API, one that supports the official Python DBI (database interface), one for the popular SQLAlchemy Python SQL Toolkit, and for the Python-based Django Web Framework. In an older blog 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.


City Information stored in Db2
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 which you can find at https://github.com/data-henrik/cloud-sql-database. The included README takes you through all the steps from provisioning a Db2 database on the IBM Cloud, over 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 tutorial "SQL Database" in the docs for IBM Cloud.

I hope you enjoy it. If you have feedback, suggestions, or questions about this post, please reach out to me on Twitter (@data_henrik) or LinkedIn.

1 comment:

Mark Ryan said...

Nice work - I think this will be very useful. Thanks very much for sharing this!

LinkWithin

Related Posts with Thumbnails