Learning Python Network Programming

(Sean Pound) #1
Chapter 9

The much stronger requirement is to build a web service application to generate
some dynamic content, and to get it up and running quickly. In this situation,
Python provides us with some excellent options in the form of web frameworks.


Web frameworks


A web framework is a layer that sits between the web server and our Python code,
which provides abstractions and streamlined APIs to perform many of the common
operations of interpreting HTTP requests and generating responses. Ideally, it is
also structured so that it guides us into employing well-tested patterns for good
web development. Frameworks for Python web applications are usually written in
Python, and can be considered part of the web application.


The basic services a framework provides are:



  • Abstraction of HTTP requests and responses

  • Management of the URL space (routing)

  • Separation of Python code and markup (templating)


There are many Python web frameworks in use today, and here's a non-exhaustive
list of some popular ones, in no particular order:



  • Django (www.djangoproject.com)

  • CherryPy (www.cherrypy.org)

  • Flask (flask.pocoo.org)

  • Tornado (www.tornadoweb.org)

  • TurboGears (www.turbogears.org)

  • Pyramid (www.pylonsproject.org)


An up-to-date list of frameworks is maintained at http://wiki.
python.org/moin/WebFrameworks and http://docs.python-
guide.org/en/latest/scenarios/web/#frameworks.

There are so many frameworks because there are many approaches that can be taken
to the tasks they perform, and many different opinions about what tasks they should
even perform.

Free download pdf