Comparing Python web frameworks

Python is known for its great web frameworks. There is a running joke at PyCon, which is that you can never work as a full-time Python developer without working on any of the Python web frameworks. There are annual conferences held for DjangoCon, one of the most popular Python frameworks. It attracts hundreds of attendees every year. If you sort the Python web frameworks on https://hotframeworks.com/languages/python, you can see there is no shortage of choices when it comes to Python and web frameworks.

Python Web Frameworks Ranking

With so many options to choose from, which one should we pick? Clearly, trying all the frameworks out yourself will be time consuming. The question about which web framework is better is also a passionate topic among web developers. If you ask this question on any of the forums, such as Quora, or search on Reddit, get ready for some highly opinionated answers and heated debates.

Both Quora and Reddit were written in Python. Reddit uses Pylons (https://www.reddit.com/wiki/faq#wiki_so_what_python_framework_do_you_use.3F), while Quora started with Pylons then replaced some with their in-house code (https://www.quora.com/What-languages-and-frameworks-are-used-to-code-Quora).

Of course, I have my own bias toward language and web frameworks. But in this section, I hope to convey to you my reasoning behind choosing one over the other. Let's pick the top two frameworks from the HotFrameworks list earlier and compare them:

  • Django: The self-proclaimed web framework for perfectionists with deadlines is a high-level Python web framework that encourages rapid development and a clean, pragmatic design (https://www.djangoproject.com/). It is a large framework with prebuilt code that provides an administrative panel and built-in content management.
  • Flask: This is a microframework for Python and is based on Werkzeug, Jinja2, and good intentions (http://flask.pocoo.org/). By micro, Flask intends on keeping the core small and the language easy to extend when needed; it certainly does not mean that Flask is lacking in functionality.

Personally, I find Django a bit difficult to extend, and most of the time, I only use a fraction of the prebuilt code. The idea of keeping the core code small and extending it when needed is very appealing to me. The initial example on the documentation to get Flask up and running consists of only eight lines of code and are easy to understand, even if you don't have any prior experience. Since Flask is built with extensions in mind, writing your own extensions, such as decorator, is pretty easy. Even though it is a microframework, the Flask core still includes the necessary components, such as a development server, debugger, integration with unit tests, RESTful request dispatching, and such, to get started out of the box. As you can see, besides Django, Flask is the second most popular Python framework by some measure. The popularity that comes with community contribution, support, and quick development helps it further.

For the preceding reasons, I feel Flask is an ideal choice for us when it comes to building network web services.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.97.53