Python Web Frameworks: An Overview of Django vs Flask vs Tornado vs Pyramid

Reading guide

The text is accompanied with questions and observations at the end, such that notes of the form (Q#) correspond to the question number # on the list. In the same fashion (O#) indicates the observation number #.


Notes on Flask

http://flask.pocoo.org/ https://github.com/pallets/flask

  • Flask is a (Q1)microframework for Python based on Werkzeug(Q2), Jinja 2(Q3) and good intentions.
  • BSD Licensed.
  • Latest release 0.12.2 (github tag).
  • Flask is minimalistic, so it doesn’t decide for you what to use, it lets you to use extensions provided the task you need. Jinja2 (R2) template engine can be changed if desired.
  • Python3 is not fully supported [Res 5]
  • Needs extensions for form validation, databases, uploads, user authentication, and other features [Res 5]
  • The docs are more accesible than Django.
  • Manages simple apps (one page apps) but it could be extended to larger.
  • Simple syntax to get an app up and running.
  • Aims to solve security issues [Res 5].

Notes on Django

https://www.djangoproject.com/ https://github.com/django/django

  • Lots of developers (github contributors)
  • “_Django is a high-level Python Web framework(Q5) that encourages rapid development and clean, pragmatic design. _” [Res 6]
  • Supported by its own foundation.
  • Current version 2.0.1.
  • Huge documentation.
  • Manages either simple or complex projects.
  • The syntax is more complex than flask.
  • Handles Databases, user authentication, form validation, amongst other features.
  • Allegedly aimed to fast development. [Res 6]
  • Has several official tutorials.

Notes on Tornado

http://www.tornadoweb.org/ https://github.com/tornadoweb/tornado

  • Tornado is a Python web framework(R5) 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.” [Res 7]
  • Moderate community.
  • The Tornado web framework(R5) and HTTP server together offer a full-stack alternative to WSGI(R4).” . [Res 8]
  • In order to run an app code complexity is higher than Flask but lower than django.
  • Has a “web framework” maybe suitable to develop webapplications.

Notes on Pyramid

https://trypyramid.com/ https://github.com/Pylons/pyramid

  • Can be conceived as Megaframework or microframework so it could be more versatile at the moment of implementation. “Megaframeworks make decisions for you. But if you don’t fit their viewpoint, you end up fighting their decisions. Microframeworks force no decisions, making it easy to start. But as your application grows, you’re on your own. In both cases, the focus is on the start: either too much or too little. Either way, finishing and staying finished is hard. You need a finishing-focused framework with an architectural design that scales down to getting started, then up as your application grows.”. [Res 9]
  • Moderate github community, grater than tornado but far smaller than Django.
  • Allows from single-file webapps to complex escalated projects.
  • Code readability looks good.

Final remarks

It seems that Django is the more popular webframework, besides, the more requested in job applications. Nevertheless, I like Tornado and Pyramid in the sense that Tornado deals with higher demanding tasks and Pyramid deals with the problem of scalability well. The caveat is that most frameworks are WSGI whilst Tornado changes the paradigm, which could be counterproductive at the moment of migrating to other frameworks.


Questions and Responses

Q1. What is a microframework?.
R1. “Typically, a microframework facilitates receiving an HTTP request, routing the HTTP request to the appropriate controller, dispatching the controller, and returning an HTTP response. Microframeworks are often specifically designed for building the APIs for another service or application.” [Res 1] (O1) See Q5 -> What is a Framework?

Q2. What is Werkzeug? R2. “Werkzeug is a WSGI(Q4) utility library for Python. It’s widely used and BSD licensed.” [Res 2]

Q3. What is Jinja2?. R3. “Jinja2 is a modern and designer-friendly templating language for Python, modelled after Django’s templates” [Res 3]

Q4. What WSGI stands for?.
R4."Web Server Gateway Interface (WSGI) is a specification for simple and universal interface between web servers and web applications or frameworks for the Python programming language." [Res 4]

Q5. What Is a Framework? R5."A framework provides capabilities that developers can enhance or extend. A web application framework provides many of the common needs of building web applications allowing developers to concentrate only on the parts that are specific to their application. Every framework makes choices about how a particular problem should be solved. When developers choose to use a framework, they cede control over the portions of their application that are provided by the framework. It is possible to write a complete web application without any framework, by using Python libraries. In practice, however, it is often more practical to use a framework, so long as your chosen framework fits the requirements of your application."
[Res 9]

Observations

  1. express for NodeJS is a microframework itself.

Resources

  1. https://en.wikipedia.org/wiki/Microframework
  2. http://werkzeug.pocoo.org/
  3. http://jinja.pocoo.org/docs/2.10/
  4. https://en.wikipedia.org/wiki/Web_Server_Gateway_Interface
  5. http://flask.pocoo.org/docs/0.12/foreword/
  6. https://www.djangoproject.com/
  7. http://www.tornadoweb.org/en/stable/
  8. http://www.tornadoweb.org/en/stable/guide/intro.html
  9. https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/introduction.html
comments powered by Disqus