Python and web technologies

Hello

Python and web technologies

Python as a general purpose language

  • OOP and functional
  • Scripting
  • Security
  • Scientific Python
  • Big data
  • Teaching tool
  • "Glue" for several pieces
  • Web

Python and web

Web = Backend and Frontend

  • Frontend - Javascript undisputed leader
  • Frontend - fullstack languages (Clojure*, NodeJS)
  • Frontend - Python? (http://www.brython.info/)

Python and web so far means only backend. Python needs more technologies in the front side to build webs: Javascript, Backbone, AngularJS, React...

Python and web

Python and backend

  • Libraries and utilities
  • Frameworks
  • Platforms

Libraries and utilities

  • Requests: HTTP library "for human beings" (http://docs.python-requests.org/en/latest/)
  • Gunicorn: Python app server (http://gunicorn.org/)
  • Werkzeug: WSGI utility library (http://werkzeug.pocoo.org/)
  • Twisted: library to build asynchronous web applications (https://twistedmatrix.com/trac/)

Frameworks

On top of libraries and utilities

A Web framework is a set of utilities with inner consistency which provide a simple way to solve common issues in web development: authentication, ddbb access, template rendering, request and response management, sessions...

A web framework is the tool and the opinion and good practices around

Platforms

Business on top of a framework

  • Nikola (https://getnikola.com/)
  • Pelican (http://blog.getpelican.com/)
  • PuPut (https://github.com/APSL/puput)
  • Django-CMS (http://www.django-cms.org/en/)
  • Symposion (https://github.com/pinax/symposion)

Frameworks - BottlePy

http://bottlepy.org/docs/dev/index.html

Is: a microframework whose potential resides in fast prototyping and small websites

Is not: the tool for big applications

Has: Routing, Templates, Utilities (forms, file uploads, cookies, headers...), Server (wsgi)

Who: me!

Frameworks - BottlePy

Hello world


from bottle import route, run, template

@route("/hello/")
def index(name):
    return template("Hello {{name}}!", name=name)

run(host="localhost", port=8080)
http://localhost:8080/hello/world

Frameworks - Flask

http://flask.pocoo.org/

Is: a microframework running over Werkzeug, with Jinja templates "and good intentions".

Is not: full of features out of the box

Has: built in development server and debugger, unit testing support, RESTful, Jinja2 templating, support for secure cookies, 100% WSGI 1.0 compliant, extensively documented

Who: http://flask.pocoo.org/community/poweredby/ (Dominion clone!!)

Frameworks - Flask

Hello world


from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()
http://localhost:5000/

Frameworks - Pyramid

http://www.pylonsproject.org/

Is: component ecosystem, with Pyramid as web framework. Small core unopinionated.

Is not: as mature as Django although it competes with Django

Has: fast prototyping, decorators based configuration, routing, debugger, add-ons...

Who: http://www.quora.com/Who-uses-the-Pyramid-framework-for-web-applications-And-how HOT-OSM, Reddit, Mozilla

Frameworks - Pyramid

Hello world


from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response


def hello_world(request):
    return Response('Hello %(name)s!' % request.matchdict)

if __name__ == '__main__':
    config = Configurator()
    config.add_route('hello', '/hello/{name}')
    config.add_view(hello_world, route_name='hello')
    app = config.make_wsgi_app()
    server = make_server('0.0.0.0', 8080, app)
    server.serve_forever()
http://localhost:8080/

Frameworks - Django

https://www.djangoproject.com/

Is: the reference tool for web development with Python

Is not: free of strong opinion; famous for front integration

Has: everything, built-in or libraries (DRF), community!!

Who: Taiga, Guía Repsol, Disqus, Pinterest... (http://codecondo.com/popular-websites-django/)

Extra Bonus - Beyond the framework

Anillo (https://github.com/jespino/anillo)

Which framework should I choose?

Questions?

(@yamila_moreno)