Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Quick and Dirty Python Deployments with Heroku


Published on

Quickly build and deploy your own web apps to Heroku using these free and easy Python tools.

Published in: Technology
  • I also left out some gotchas I discovered early on: Heroku uses ./lib and ./bin as magic directories so if you put some of your assets there you'll be confounded by unexpected caching that persists from one deploy to the next. Better to avoid it by renaming your directories.
    Are you sure you want to  Yes  No
    Your message goes here
  • The links appear to be messed up in the presentation, so here they are again:
    Are you sure you want to  Yes  No
    Your message goes here

Quick and Dirty Python Deployments with Heroku

  1. Quick and Dirty PythonDeployments with HerokuGuest starring Flask, CoffeeScript, Fabric, and SeatGeek Daniel Pritchett for MEMpy, March 19, 2012
  2. Painless Heroku Startup
  3. Requirements• Python 2.7• virtualenv• pip• Rubygems• Procfile / foreman
  4. Get started• Install git, foreman, pip, virtualenv• Clone/create a repo with a Procfile that starts a HTTP service• foreman start to test it locally• heroku create app_name – stack=cedar && git push heroku master
  5. Setup log$ virtualenv --no-site-packages heroku_demo New python executable in heroku_demo/bin/python Installing pip...............cdone.$ cd heroku_demo/$ . bin/activate$ git clone git:// app$ cd app$ pip install -r ./requirements.txt Successfully installed Flask Jinja2 Pygments Werkzeug chardet gunicorn$ foreman start 13:20:18 web.1 | started with pid 17810 13:20:18 web.1 | 2012-03-19 13:20:18 [17810] [INFO] Starting gunicorn 0.14.1 13:20:18 web.1 | 2012-03-19 13:20:18 [17810] [INFO] Listening at:$ heroku create mempy-demo --stack=cedar Creating mempy-demo... done, stack is cedar | Git remote heroku added$ git push heroku master Procfile declares types -> web deployed to Heroku$ curl Hello World!
  6. Foreman’s Procfile defines the serviceweb: gunicorn app:APP -b$PORT -w 3You can run the same thing at the console to test: $ gunicorn app:APP -b$PORT -w 3
  7. Heroku logging• Captures stdout, stderr• You’ll need it since you have no persistent disk• Simplest case you can just use a print statement• Free plan has limitations• Consider an offsite log manager
  8. Remote console$ heroku run bash Running bash attached to terminal... up, run.2~ $ find templates templates templates/index.html~ $ find static static static/js static/js/memphis_tickets.js static/coffee static/coffee/ static/bootstrap static/bootstrap/js static/bootstrap/js/bootstrap.js ... static/bootstrap/css/bootstrap.css static/css static/css/tickets.css~ $
  9. Sample Flask application:
  10. The entire backend
  11. HTML templating (Jinja2)
  12. CoffeeScript excerpts
  13. Data provided by SeatGeek API
  14. Honorable mention: Fabric $ fab s [localhost] local: coffee -o ../js/ --compile ./*coffee [localhost] local: foreman start 14:11:29 web.1 | started with pid 24218 14:11:29 web.1 | 2012-03-19 14:11:29 [24218] [INFO] Starting gunicorn 0.14.1 14:11:29 web.1 | 2012-03-19 14:11:29 [24218] [INFO] Listening at: (24218) 14:11:29 web.1 | 2012-03-19 14:11:29 [24218] [INFO] Using worker: sync 14:11:29 web.1 | 2012-03-19 14:11:29 [24225] [INFO] Booting worker with pid: 24225 14:11:29 web.1 | 2012-03-19 14:11:29 [24226] [INFO] Booting worker with pid: 24226 14:11:29 web.1 | 2012-03-19 14:11:29 [24227] [INFO] Booting worker with pid: 24227
  15. Heroku EcosystemPain points and add-ons
  16.• Databases• Worker hours• Email services• DNS• HTTPS and certificates• Billing• Message/Task Queues
  17. LogEntries
  18. LogEntries Alerts
  19. Zerigo DNS
  20. MongoHQ
  21. Thank you!Try a copy of the code at and Flask have great docs.Find me @dpritchett