Pyramid, Bottle and Tornado
26 Nov 2016As web application developers, we’re given a vast array of web application development frameworks at our disposal, In today’s post, I’m going to go through three of these; all based on the Python programming language. The frameworks are:
These really are micro-frameworks for this purpose.
Pyramid
Pyramid, or the Pylons Project is a straight-forward application framework where most of the focus is placed on the application’s configuration. This isn’t an ancillary file supplied to the application, but defined in code, in module. From the web site:
Rather than focusing on a single web framework, the Pylons Project will develop a collection of related technologies. The first package from the Pylons Project was the Pyramid web framework. Other packages have been added to the collection over time, including higher-level components and applications. We hope to evolve the project into an ecosystem of well-tested, well-documented components which interoperate easily.
The Pylons project is a greater umbrella for the Pyramid-piece which is the web application framework.
Following is a “Hello, world” application using this framework.
The Configurator
class holding a lot of the application’s runtime, which is where routes and views come together.
Bottle
Bottle is a no-frills framework, with four main responsibilities: routing, templates, utilities and server.
It’s actually quite amazing (from a minimalist’s perspective) exactly how much you can get accomplished in such little code. Here’s the “Hello, world” example from their site:
The simplistic feel to the framework certainly makes it very clear. template
providing a direct text template with a model. run
performing the job of the server and the @route
attribute performing route configuration.
They’re faithful to their words:
Bottle is a fast, simple and lightweight WSGI micro web-framework for Python. It is distributed as a single file module and has no dependencies other than the Python Standard Library.
Tornado
Tornado is a web application framework that has been based around event-driven I/O. It’s going to be better suited to some of the persistent connection use-cases that some applications have (like long-polling or web sockets, etc). The following is from their site:
Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed. By using non-blocking network I/O, Tornado can scale to tens of thousands of open connections, making it ideal for long polling, WebSockets, and other applications that require a long-lived connection to each user.
In its own way, Tornado can also be quite minimalist. Here’s their example:
Key difference on this particular framework is the involvement of the IOLoop
class. This really is event-driven web programming.