Hello World on Bluemix With Python

Getting Started

Get an account

Access bluemix Web site here:
Click on the “Sign Up” for Bluemix button.
Read quick start

Installing the cf tool

Before you begin, install the command line tool that is used to upload and manage your application. BlueMix uses a tool called cf command line interface.
Download cf command line interface from
The cf command is a program that you need to install. Select the appropriate installer for your operating system. After the cf command tool is installed, you can use cf -v command to verify its version as follows:

$cf -vcf version 6.0.0-90db382

Login using the cf tool

Login. Be sure to use the right endpoint. To see the end point type:

$cf –t
API endpoint: (API version: 2.2.0)Not logged in. Use 'cf login' to log in.
$cf login

I had to reset mine to the beta site.

$ cf api

Important files

Procfile is where the command is for launching your app

Web: python s the contents of your hello world app

import os
from flask import Flask
app = Flask(__name__)
def hello():
    return 'Hello World!'
    port = os.getenv('VCAP_APP_PORT', '5000')
if __name__ == "__main__":'', port=int(port))

Get help getting answers to your questions

Go to forums

Prepare the environment for your chosen runtime

Python is my language of choice. Bluemix doesn’t have Python as a pre-existing runtime. You can however create your own runtime by using buildpacks that create the environment for you.   In this hello world example we will use Flask as our HTTP server.
requirements.txt file describes the application prequisites.


You can push your application to Bluemix along with a Python buildpack:
You can find Python buildpacks on Github. From this page you can click on the Download Zip file on the right column.
Unzip the file into a local directory. Extract the zip into directory named hello-python-master in the folder where cf tool was installed in.


Push App to Bluemix

cf push <YOUR_APP_NAME> -m 128M -b
$ c:\CloudFoundry\hello-python-master>cf push hello-python-master -m 128M -b

Check the logs in the command window for errors. You likely might get some because you aren’t executing the commands in the right folder. Make sure you invoke the command where the requirements.txt file is for the file. If successful you should see the output below.

…-----> Uploading droplet (26M) 0 of 1 instances running, 1 starting1 of 1 instances running 
App started Showing health and status for app hello-python-master in org carlos.ferreira@ / space dev as
OK requested state: startedinstances: 1/1usage: 128M x 1 instancesurls:      
state     since                   cpu   memory           disk#0   
running   2014-05-08 09:51:17 PM   0.0%   109.4M of 128M   99M of 1G

Try your App in the browser

Open a browser and type the name of the app pre-pended to your Bluemix URL.
My app is hello-python-master
My Bluemix URL is
Figure 1 Hello World
Check the logs in the command line window
Check your dashboard on bluemix that the app is running

Figure 2. 1 Bluemix Dashboard
Took me about 1.5 hours to get the app running.   This was much faster than my hello world experience with Heroku.


2 thoughts on “Hello World on Bluemix With Python

  1. Maddie Von says:

    I think in the source code of the file there is at least one type – the last two lines probably should be

    if __name__ == ‘__main__’:’′, port=int (port))

    instead of

    if __name__ == “__main__”:’

    But even after correcting this, I couldn’t get it running. In the end I used this source code:
    (from this tutorial: )

    and with that it worked.

    • Carlos says:

      Hi Maddie, There are different ways you can deploy a Python processes. This example allows you to run a python process that behaves like a Web server. This is fine for Web Development but not production. There are other deployment models that include or provide a web container like the one you mention Flask. And others like Thanks for sharing. I don’t believe you need to modify the “” code. In the version you tried you also had an additional step to bind the postgres service to your web app. In the latest version I modified the manifest file to also declare the postgres service and bind to it. So there should not be any additional manual binding step now to deploy/run your app. Also that other sample you suggest doesn’t include Django or create the Admin user in your database so that you can then add other users through the Django Admin site

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s