Skip to Content

Getting started with Python development – Bring Your Own Language

In the world of Cloud Foundry, buildpacks provide necessary runtime and framework support for your application to run. The artifacts mentioned in the manifest file are used to determine the buildpack and the command necessary to run the application. SAP Cloud Platform supports the concept of BYOL (Bring Your Own Language) where the users can System buildpacks or the community buildpacks that are possible to be run on Cloud Foundry environment.

In this blog, we will have a look at one such development where we will use the Cloud foundry system buildpack. We will develop and deploy a simple Python application using the python buildpack to the SAP Cloud Platform Cloud Foundry environment.

In this blog, you will learn the following:

  • Deploying a simple Python application on SAP Cloud Platform
  • Consuming the buildpack that is not available in SAP Cloud Platform (BYOL)
  • Project structure/files required to deploy the python application

About the project

In this tutorial, we will use the following framework and server module to develop a web application that displays a simple message.


This application uses flask which is a web development framework for Python.  This framework also helps to define the port in which you want the application to run. In the main application file, we will use the following lines of code to use the flask library and define the port.

from flask import Flask
import os
app = Flask(__name__)
port = int(os.getenv("PORT", 9009))
if __name__ == '__main__':'', port=port)


Now that we have defined the framework for web development, we need a Web Server Gateway Interface (WSGI) that acts as an interface between the framework and the web server. Gunicorn is a Python WSGI HTTP Server.

Both the dependencies – Gunicorn and Flask must be provided in the requirements.txt file. The project structure looks like this:




  • The is the actual Python script file or the application that contains the application logic. This is where the Flask related details are coded. A sample code is as depicted below:
This is my first python application that is being deployed on SAP Cloud Platform in the Cloud Foundry environment
from flask import Flask
import os

app = Flask(__name__)

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

def hello_world():
	return 'Hello World! Welcome to SAP Cloud Platform'

if __name__ == '__main__':'', port=port)
  • As with any Cloud Foundry application, we can deploy the application with the manifest.yml file that contains the information about the application artifacts. Below is a sample of what can be coded for Python deployment.
- name: myfirstapp
  memory: 128M
  command: python

Note the buildpack reference provided in the manifest file. SAP Cloud Platform takes this buildpack for the runtime container of this application.

  • The requirement file contains the information about the dependent libraries.

Flask (or)


The requirement file would just simply contain the library name. Example: If Flask is required, the file would have the word “Flask”.

Deploying the application

The application can now be deployed from the Cloud Foundry Command Line Interface using the cf push command. It uses the manifest.yml file for the deployment.


For the sake of understanding the process of deployment, go through the prompts in the window.

  • The tool reads the manifest.yml to understand the application artifacts like application name, buildpack, etc.
  • The route URL to access the application in SAP Cloud Platform is created
  • The application is bound to the route
  • The application source code is then uploaded
  • The application is started and then the health is monitored
  • The application details like the memory consumption, number of instances, URL, etc. are summarized.

The details of the application can be viewed in the SAP Cloud Platform cockpit.

Upon launching the application URL, the Hello World message is displayed successfully.

You must be Logged on to comment or reply to a post.
  • Thank you for a helpfull article. Python is a great language to be involved in the world of programming. And the BYOL concept of SAP Cloud Platform and the possibility to build an application which will be run on Cloud Foundry environment. As I've read from Iflexion BLog Python is a good solution to build analytical applications. And if to speak about its flexibility and wide usage I'll probably try to build my own application using your advice and comments.


  • Thanks for the tutorial.


    Few comments.

    The screenshots are small and hard to read. I have to zoom to read them.

    The exact content of requirements.txt is not clear.

    It is not clear where Gunicorn is used. I see only Flask referenced in the code.

    • Hi Petar,

      Thanks for the comments. I have updated the blog. The requirements.txt would simply contain the word "Flask". And we can either use Flask or if there is a bigger requirement, we could use Gunicorn.

  • I just recently started working for an IT company that is developing software, I'm just learning, but for me this article was very useful and informative. Thank you.

  • Dont know why I'm getting this error while executing the same code what you have shown here.


    -----> Running go build finalize
    No start command specified by buildpack or via Procfile.
    App will not start unless a command is provided at runtime.
    Exit status 0
    Uploading build artifacts cache...
    Uploading droplet, build artifacts cache...
    Uploading droplet...
    Uploaded build artifacts cache (1.1M)
    Uploaded droplet (40.1M)
    Uploading complete
    Stopping instance 0dc7efea-c131-4001-9176-2101b83b6cf6
    Destroying container
    Successfully destroyed container

    0 of 1 instances running, 1 crashed
    Error restarting application: Start unsuccessful

    TIP: use 'cf logs hello-unique --recent' for more information

  • Hi Hariprasauth R

    I need your help in fixing the issues to establish a connection with HDI container from Python application.


    I am using hdbcli package of python which is delivered by SAP .


    I downloaded XS PYTHON file from SAP Market Place and did a pip locally


    When I am trying to deploy the application in cloud foundry it is again trying to do a PIP while deployment as well. I get the below error.


    Collecting hdbcli (from -r /tmp/contents263672840/deps/0/requirements.txt (line 3))
    2018-10-09T07:16:09.426+0000 [STG/0] ERR Could not find a version that satisfies the requirement hdbcli (from -r /tmp/contents263672840/deps/0/requirements.txt (line 3)) (from versions: )
    2018-10-09T07:16:09.428+0000 [STG/0] ERR No matching distribution found for hdbcli (from -r /tmp/contents263672840/deps/0/requirements.txt (line 3))
    2018-10-09T07:16:09.450+0000 [STG/0] OUT pip install has failed. You have a vendor directory, it must contain all of your dependencies.
    2018-10-09T07:16:09.450+0000 [STG/0] OUT [31;1m**ERROR**[0m Could not install pip packages: Couldn’t run pip: exit status 1


    I have attached my code for your Reference.

    import os
    from flask import Flask
    from cfenv import AppEnv
    from hdbcli import dbapi
    app = Flask(__name__)		
    env = AppEnv()		
    port = int(os.environ.get('PORT', 3000))
    hana = env.get_service(name='hdi-db')	
    def hello():
        #connect to DB using credentials from hdi-db service
        conn = dbapi.connect(address=hana.credentials['host'],
                             port= int(hana.credentials['port']),
                             user = hana.credentials['user'],
                             password = hana.credentials['password'],
        cursor = conn.cursor()
        #execute SQL query
        cursor.execute("select CURRENT_UTCTIMESTAMP from DUMMY", {})      
        ro = cursor.fetchone()        #get the first result
        conn.close()        #close DB connection
        #return query results
        return "Current time is: " + str(ro["CURRENT_UTCTIMESTAMP"])  
    if __name__ == '__main__':



    - name: pyapp
      host: pyappvig1
      path: .
      command: python
       - hdi-dbvig

    These are packages there under vendor folder after a PIP command


    This is my Project Structure :




    Vignesh Jeyabalan

  • Thanks for your case. Python EPP deployment theme is very close to me. By the way, if you want to read more about cases related to date, you can look at the blog of the GreenM company there are both business articles and technical ones. I would advise looking at the technical ones. These guys provide highly specialized services in the Team Extension for your Data Initiatives format, so there are very interesting materials there.

  • Hey, Hari's thanks man for sharing such a diligent article on python development .I am learning new languages for web and app development. I am very much fond of technology and love to read and write blogs on it. Keep sharing posts like these.Cheers!!

  • Hariprasauth, thanks for the detailed guide on the application development and deployment. That helps me much when building on Cloud Foundry.
    Not related to the article, what databases or cloud provider you would choose for a large-loaded project when the budget is tight?
    I looked over this overview of serverless architecture options, but still, hesitate what option we should choose for our newbie project?

  • Well, I think this is a very interesting topic, and I think that you will also be interested in this topic