In this tutorial, you’ll have a look at how to create and publish a Python Flask web application on GE Predix platform.

Predix is an industrial IOT platform developed by GE to connect data from physical assets and machines to the cloud to analyze and assess different trends. It’s really useful in analyzing machine data and providing useful analytics.
From the official page,

Predix is the Industrial Internet platform that connects data from physical assets to powerful analytics. Predix can operate everywhere industry does, allowing you to quickly and securely connect their assets, collect data, and run applications.

Python Flask Web Application On GE Predix

Create a folder called PythonPredix. Navigate to the project directory and create a file called manifest.py which would contain the details of the application. Here is how the manifest.py file looks:

applications:
  - name: codehandbook
    buildpack: python_buildpack 
    memory: 256M
    stack: cflinuxfs2

As seen in the above configuration, you have named the application as codehandbook. You have defined the buildpack as python_buildpack which is the default build pack for Python applications.

Create a file called app.py which would contain our application code. Import the Flask module and create a default route which would display a message. Here is how app.py file looks:

from flask import Flask
import os

app = Flask(__name__)

port = int(os.getenv("PORT", 3000))

@app.route('/')
def hello_world():
    return 'Welcome Flask on Predix :)' 

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=port)

The Python application would require a file called requirements.txt which would contain the dependencies which needs to be installed to run the Python application. Since in this case you are only using Flask, create a file called requirements.txt in the PythonPredix project directory and add the following content:

Flask

Now when the code gets pushed to Predix, it needs to know the command which is required to start the Python application. You need to specify that command in a separate file called Procfile. Create a file called Procfile and add the following command:

web: python app.py

Now you are ready to push the Python Flask application to the Predix platform. Log in to the cloud foundry and push the Python code using the following command:

cf push

Once successfully pushed you should have the application running. Here is the URL to my Python Flask Web application on GE Predix. https://codehandbook.run.aws-usw02-pr.ice.predix.io/

Source code from this tutorial is available on GitHub.

Wrapping It Up

In this short tutorial, you saw how to publish a Python Flask Web Application on GE Predix platform. Have you used the GE Predix platform for any Python web application project ? How was your experience ? Do let us know your thoughts in the comments below.