Python on 
Cloud Foundry 
Ian Huston, Data Scientist 
@ianhuston 
© Copyright 2014 Pivotal. All rights reserved. 1
Who am I? 
Ÿ Ian Huston 
Ÿ @ianhuston 
Ÿ github.com/ihuston 
Ÿ www.ianhuston.net 
Ÿ Talk resources: 
http://tinyurl.com/pythonCF 
@ianhuston 
Ÿ Data Scientist 
Ÿ Use PyData stack for 
predictive analytics and 
machine learning 
Ÿ Previously a theoretical 
physicist using Python for 
numerical simulations & HPC 
© Copyright 2014 Pivotal. All rights reserved. 2
What is Cloud Foundry? 
@ianhuston 
http://cloudfoundry.org 
Open Source Cloud Platform 
Simple App Deployment, 
Scaling & Availability 
© Copyright 2014 Pivotal. All rights reserved. 3
Cloud Foundry Foundation: Industry Standard 
@ianhuston 
Gold 
Silver 
© Copyright 2014 Pivotal. All rights reserved. 4
CF for data scientists & developers 
Easily deploy your web app 
Scale up and out quickly 
Create and bind services 
cf 
bind-­‐service 
myapp 
redis 
@ianhuston 
cf 
push 
cf 
scale 
myapp 
–i 
5 
–m 
1G 
© Copyright 2014 Pivotal. All rights reserved. 5
Cloud Foundry: From 50 touch points to 1 
1 2 4 4 40 1 
50 Configuration Touches 
1. Register Hostname with DNS (1) 
2. Configure F5 Load Balancing Group (2) 
3. Configure Apache HTTPd Worker Pool (4) 
4. Configure mod_proxy Connector Routing (4) 
5. Configure Tomcat Connector Pool (40) 
@ianhuston 
mod proxy 
1 Configuration Touch 
1. The platform takes care of all the steps on 
the left automatically 
© Copyright 2014 Pivotal. All rights reserved. 6
Python & CF 
@ianhuston 
© Copyright 2014 Pivotal. All rights reserved. 7
Python on Cloud Foundry 
Ÿ First class language (with Go, Java, Ruby, Node.js, PHP) 
Ÿ Automatic app type detection 
Ÿ Buildpack takes care of 
– Installing Python interpreter 
– Installing packages in requirements.txt using pip 
– Starting web app as requested (e.g. python myapp.py) 
@ianhuston 
© Copyright 2014 Pivotal. All rights reserved. 8
Simple Flask App Demo 
Ÿ Simple one page “Hello World” web app 
Ÿ Video: https://www.youtube.com/watch?v=QOfD6tnoAB8 
Ÿ Demonstrates: 
– Installation of requirements 
– Scaling properties 
Ÿ Need to Provide: 
– App files 
– Dependencies listed in requirements.txt file 
– Optional manifest.yml file with configuration for deployment 
@ianhuston 
© Copyright 2014 Pivotal. All rights reserved. 9
Data Services 
Ÿ Easy to bind and scale services 
– Databases, NoSQL, message queues etc. 
$ 
cf 
create-­‐service 
rediscloud 
PLAN_NAME 
INSTANCE_NAME 
$ 
cf 
bind-­‐service 
APP_NAME 
INSTANCE_NAME 
Ÿ Details provided in VCAP_APP_SERVICES env variable: 
{ 
"rediscloud": 
[ 
{ 
"name": 
"rediscloud-­‐42", 
"label": 
"rediscloud", 
"plan": 
"20mb", 
"credentials": 
{ 
"port"": 
"6379", 
"hostname": 
"pub-­‐redis-­‐6379.us-­‐east-­‐1-­‐2.3.ec2.redislabs.com", 
} 
@ianhuston 
"password": 
"your_redis_password” 
} 
} 
] 
© Copyright 2014 Pivotal. All rights reserved. 10
Services now available 
These are available on Pivotal CF (Pivotal’s packaged Cloud Foundry offering). 
See http://run.pivotal.io for the services available on Pivotal Web Services. 
@ianhuston 
© Copyright 2014 Pivotal. All rights reserved. 11
PyData stack on CF: conda 
• Use (mini)conda to provide Python & package 
installation 
• Quickly install needed PyData packages 
• Can even provision your own IPython notebook 
server [at your own risk!] 
CF Buildpack: https://github.com/ihuston/python-conda-buildpack 
@ianhuston 
+ 
© Copyright 2014 Pivotal. All rights reserved. 12
Why? 
@ianhuston 
© Copyright 2014 Pivotal. All rights reserved. 13
Benefits for Data Scientists 
Ÿ Easy to get web apps up and running 
Ÿ Create and bind to your favourite data services 
Ÿ Don’t get locked in to one cloud provider 
Ÿ Python is officially supported 
@ianhuston 
© Copyright 2014 Pivotal. All rights reserved. 14
Try Cloud Foundry today! 
Pivotal Web Services: http://run.pivotal.io 
HP Helion: http://horizon.hpcloud.com 
@ianhuston 
IBM Bluemix: http://bluemix.net 
Anynines: http://anynines.com 
© Copyright 2014 Pivotal. All rights reserved. 15
More info and resources 
Ÿ Material for this talk: http://tinyurl.com/pythonCF 
Ÿ Cloud Foundry: http://cloudfoundry.org 
Ÿ Flask Mega Meta Tutorial for DS: http://tinyurl.com/flaskDS 
Ÿ Twelve Factor Apps: http://12factor.net/ 
Ÿ Meetups: http://cloud-foundry.meetup.com/ 
@ianhuston 
© Copyright 2014 Pivotal. All rights reserved. 16
Appendix 
Docker & Cloud Foundry 
@ianhuston 
© Copyright 2014 Pivotal. All rights reserved. 17
CF and Docker 
Docker joins the Cloud 
Foundry Foundation in 
May 2014 to support 
Cloud Foundry open 
governance and advance 
the state of containers in 
Platform as a Service 
@ianhuston 
© Copyright 2014 Pivotal. All rights reserved. 18
Docker Benefit: Customize More Layers of the App 
Dev Provides 
System Provides 
App container 
@ianhuston 
Docker 
application layer 
runtime layer 
OS image 
system brings fixed 
host OS Kernel 
Buildpack 
application layer 
runtime layer* 
OS image 
system brings fixed 
host OS Kernel 
* Devs may bring a custom buildpack 
© Copyright 2014 Pivotal. All rights reserved. 19
Coming soon to Cloud Foundry 
Ÿ Planned to support Cloud Foundry apps from: 
– Linux Buildpacks 
– Windows .NET Buildpacks powered by Iron Foundry 
– Docker images 
Ÿ Docker applications will work similar to apps from buildpacks 
– Same scaling & services bindings, same CLI commands push etc 
@ianhuston 
© Copyright 2014 Pivotal. All rights reserved. 20

Python on Cloud Foundry

  • 1.
    Python on CloudFoundry Ian Huston, Data Scientist @ianhuston © Copyright 2014 Pivotal. All rights reserved. 1
  • 2.
    Who am I? Ÿ Ian Huston Ÿ @ianhuston Ÿ github.com/ihuston Ÿ www.ianhuston.net Ÿ Talk resources: http://tinyurl.com/pythonCF @ianhuston Ÿ Data Scientist Ÿ Use PyData stack for predictive analytics and machine learning Ÿ Previously a theoretical physicist using Python for numerical simulations & HPC © Copyright 2014 Pivotal. All rights reserved. 2
  • 3.
    What is CloudFoundry? @ianhuston http://cloudfoundry.org Open Source Cloud Platform Simple App Deployment, Scaling & Availability © Copyright 2014 Pivotal. All rights reserved. 3
  • 4.
    Cloud Foundry Foundation:Industry Standard @ianhuston Gold Silver © Copyright 2014 Pivotal. All rights reserved. 4
  • 5.
    CF for datascientists & developers Easily deploy your web app Scale up and out quickly Create and bind services cf bind-­‐service myapp redis @ianhuston cf push cf scale myapp –i 5 –m 1G © Copyright 2014 Pivotal. All rights reserved. 5
  • 6.
    Cloud Foundry: From50 touch points to 1 1 2 4 4 40 1 50 Configuration Touches 1. Register Hostname with DNS (1) 2. Configure F5 Load Balancing Group (2) 3. Configure Apache HTTPd Worker Pool (4) 4. Configure mod_proxy Connector Routing (4) 5. Configure Tomcat Connector Pool (40) @ianhuston mod proxy 1 Configuration Touch 1. The platform takes care of all the steps on the left automatically © Copyright 2014 Pivotal. All rights reserved. 6
  • 7.
    Python & CF @ianhuston © Copyright 2014 Pivotal. All rights reserved. 7
  • 8.
    Python on CloudFoundry Ÿ First class language (with Go, Java, Ruby, Node.js, PHP) Ÿ Automatic app type detection Ÿ Buildpack takes care of – Installing Python interpreter – Installing packages in requirements.txt using pip – Starting web app as requested (e.g. python myapp.py) @ianhuston © Copyright 2014 Pivotal. All rights reserved. 8
  • 9.
    Simple Flask AppDemo Ÿ Simple one page “Hello World” web app Ÿ Video: https://www.youtube.com/watch?v=QOfD6tnoAB8 Ÿ Demonstrates: – Installation of requirements – Scaling properties Ÿ Need to Provide: – App files – Dependencies listed in requirements.txt file – Optional manifest.yml file with configuration for deployment @ianhuston © Copyright 2014 Pivotal. All rights reserved. 9
  • 10.
    Data Services ŸEasy to bind and scale services – Databases, NoSQL, message queues etc. $ cf create-­‐service rediscloud PLAN_NAME INSTANCE_NAME $ cf bind-­‐service APP_NAME INSTANCE_NAME Ÿ Details provided in VCAP_APP_SERVICES env variable: { "rediscloud": [ { "name": "rediscloud-­‐42", "label": "rediscloud", "plan": "20mb", "credentials": { "port"": "6379", "hostname": "pub-­‐redis-­‐6379.us-­‐east-­‐1-­‐2.3.ec2.redislabs.com", } @ianhuston "password": "your_redis_password” } } ] © Copyright 2014 Pivotal. All rights reserved. 10
  • 11.
    Services now available These are available on Pivotal CF (Pivotal’s packaged Cloud Foundry offering). See http://run.pivotal.io for the services available on Pivotal Web Services. @ianhuston © Copyright 2014 Pivotal. All rights reserved. 11
  • 12.
    PyData stack onCF: conda • Use (mini)conda to provide Python & package installation • Quickly install needed PyData packages • Can even provision your own IPython notebook server [at your own risk!] CF Buildpack: https://github.com/ihuston/python-conda-buildpack @ianhuston + © Copyright 2014 Pivotal. All rights reserved. 12
  • 13.
    Why? @ianhuston ©Copyright 2014 Pivotal. All rights reserved. 13
  • 14.
    Benefits for DataScientists Ÿ Easy to get web apps up and running Ÿ Create and bind to your favourite data services Ÿ Don’t get locked in to one cloud provider Ÿ Python is officially supported @ianhuston © Copyright 2014 Pivotal. All rights reserved. 14
  • 15.
    Try Cloud Foundrytoday! Pivotal Web Services: http://run.pivotal.io HP Helion: http://horizon.hpcloud.com @ianhuston IBM Bluemix: http://bluemix.net Anynines: http://anynines.com © Copyright 2014 Pivotal. All rights reserved. 15
  • 16.
    More info andresources Ÿ Material for this talk: http://tinyurl.com/pythonCF Ÿ Cloud Foundry: http://cloudfoundry.org Ÿ Flask Mega Meta Tutorial for DS: http://tinyurl.com/flaskDS Ÿ Twelve Factor Apps: http://12factor.net/ Ÿ Meetups: http://cloud-foundry.meetup.com/ @ianhuston © Copyright 2014 Pivotal. All rights reserved. 16
  • 17.
    Appendix Docker &Cloud Foundry @ianhuston © Copyright 2014 Pivotal. All rights reserved. 17
  • 18.
    CF and Docker Docker joins the Cloud Foundry Foundation in May 2014 to support Cloud Foundry open governance and advance the state of containers in Platform as a Service @ianhuston © Copyright 2014 Pivotal. All rights reserved. 18
  • 19.
    Docker Benefit: CustomizeMore Layers of the App Dev Provides System Provides App container @ianhuston Docker application layer runtime layer OS image system brings fixed host OS Kernel Buildpack application layer runtime layer* OS image system brings fixed host OS Kernel * Devs may bring a custom buildpack © Copyright 2014 Pivotal. All rights reserved. 19
  • 20.
    Coming soon toCloud Foundry Ÿ Planned to support Cloud Foundry apps from: – Linux Buildpacks – Windows .NET Buildpacks powered by Iron Foundry – Docker images Ÿ Docker applications will work similar to apps from buildpacks – Same scaling & services bindings, same CLI commands push etc @ianhuston © Copyright 2014 Pivotal. All rights reserved. 20