Python is a general-purpose programming language which means Python is used in all kind of software from simple automation script to system programming, game development, GUI application and web applications. Recently, Python is gaining momentum as the top programming for Data science and Machine learning application. In this article, the top five Python web frameworks will explain and details information about these frameworks will be presented.

The web application has two parts, client side and server side. The client side is mainly HTML, CSS and Javascript and considered a way to present information to the user. The server-side part of the application has all the business logic and often has a complex part of the application. Server-side web development is done in many languages like Java, .Net, PHP, Ruby on Rails, Javascript etc., Python is also capturing the share of server-side development with its various web frameworks.

Developing server side in the programming language without any framework is very tedious as the developer has to write code for every repeating thing, to recuse developer and fasten the web development most of the programming has web framework. A web framework is a pre-written code for doing repeating tasks of web development and provide the abstract form for writing a web application. For example, user authentication is a pre-built feature of web framework and almost all web framework provide an abstract layer on using databases. So, web framework helps web developer to develop web application faster and more efficient with well-written modules and functionalities. Python is open source programming and many of its web frameworks are also opensource and free for example Flask, Django, web2py, bottle etc.

In this article, the top 5 Python web frameworks are discussed with sample example and other related information which will help the developer to choose the right framework for their work. Web frameworks can be grouped into two categories: Full-stack framework (many modules) and Micro-framework (thin with limited features).

1. Django

Django is a full stack web framework suitable for a large and complex project. It helps in rapid and clean development of a web project. Django is free and opensource and built & maintain by a ton of experienced web developers. According to Django documentation, some of the listed features of Django are, ridiculously fast, reassuringly secure, exceedingly scalable, and incredibly versatile.

2. Web2py

Web2py is another full-stack framework for rapid development of fast, scalable, secure and portable database-driven web-based applications.

3. Flask

Flask is a micro-framework which has Werkzeug, Jinja 2 as the core engine. It is BSD license. It is very light and suitable for a small project. Flask is also very useful for API (Application Programming Interface) development.

Here’s the sample Code:

from flask import Flask
app = Flask(__name__)

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

4. Bottle

The Bottle is a fast, simple and lightweight micro web-framework. It is distributed as a single file module and has no dependencies other than the Python Standard Library. It is good for fast prototyping and personal website.

Here’s the sample Code for Bottle:

from bottle import route, run, template

@route('/hello/<name>')
def index(name):
    return template('<b>Hello {{name}}</b>!', name=name)

run(host='localhost', port=8080)

5. CherryPy

CherryPy is a minimalist Python Web Framework. It has features like reliability, easy to run multiple HTTP servers, flexible plugin system, built-in tools for caching, encoding, sessions, authentication, static content, swappable and customizable, built-in profiling, coverage, and testing support.

Here’s the Example Code:

import cherrypy

class HelloWorld(object):
    @cherrypy.expose
    def index(self):
        return "Hello World!"

cherrypy.quickstart(HelloWorld())

Characteristics Comparison

Here’s a little comparison between all 5 frameworks listed above.

CharacteristicsDjangoWeb2pyFlaskBottleCherryPy
First Release20052007201020092002
Current/ Stable Version2.2, April 20192.17.2, October 20181.0.2,
May 2018
0.12.16,
December 2018
18.1.0, December 2018
TypeFull-stackFull-stackMicro-frameworkMicro-frameworkMicro-framework
Developer/sAdrian Holovaty, Simon WillisonMassimo Di PierroArmin RonacherMarcel HellkampRemi Delon,
Robert Brewer
Open-SourceYesYesYesYesYes
FreeYesYesYesYesYes
LicenseBSDGNU LGPLBSDMITBSD
Operating SystemCross-platformCross-platformCross-platformCross-platformCross-platform
Python VersionPython 2.x and Only Python 3.x (Django 2.0 onwards )Python 2.7 and Python 3.5+Both Python 2.x and Python 3.xPython 2.5+ and 3.xPython 2.x and Python 3.x
Popular exampleInstagram, DisqusInstant Press,
Ourway
Pinterest,
LinkedIn
Splunk Enterprise

How to choose?

We have listed only 5 Best web-framework of Python but there are so many out there. So, the genuine question would be “how to choose which framework to use?”. Giving a direct answer would be biased so apart from the above information, we have also decided some metrics regarding these frameworks which are based on GitHub, stack-overflow and naukri.com. Github and stack-overflow is developer playground so they offer few options like giving stars to project hosted on GitHub and asking question-related to CS and IT concepts on stack-overflow. On the other hands naurki.com list job opening related to technologies and required skills. We have taken four metrics out of these sites, all the metric are not very robust but could help to understand about these web-frameworks. (Note: All the value are collected from public search as on 19 June 2019.

a) Github Star: Total stars given to project by users.

b) Github releases: How many releases each project has, this reflect the active project and mature projects.

c) Stack-overflow questions: How many questions are asked for a particular topic.

d) Posted-jobs: How many job posting is there related to technologies or skills.

MetricDjangoWeb2pyFlaskBottleCherryPy
Github-stars422641769448236204991
Github-release221722773121
Stackoverflow-Questions20061020702847013501275
Posted-jobs16193362904

From the above data, one can easily understand that Django is popular in full-stack web-framework and Flask is popular in micro-framework. Other web-frameworks are also gaining popularity and can be the best choice for learning and contributing to the project or build Application on the top of these web-frameworks.

There are so many other web-frameworks based on Python like TurboGears, pyramid etc. In-depth how-to and working of these web-frameworks can be read from the website and we have also plan to publish a detailed article on these in future. Keep checking this space for the update.

Thank you for being here and keep reading…

Here’re some more Articles you might be interested:

— Here Are The Ten Best Programming Languages to learn

— Some Keeps to avoid bugs while Programming

— 10 Simple Rules For Best Programming Practices

1 Comment

Write A Comment