In this article we are going to talk about Python Top 5 Web Frameworks, as you know there are alot of Python Web Frameworks. but we are just focus on top web frameworks in python programming language.
What is a framework ?
A framework is nothing but it is a collection of modules that make development easier. They are grouped together, and allows us to create applications or websites from an existing source, instead of from scratch.
1: Django
Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. and django is suitable for both front-end and back-end. And also django is famous because of it is admin panel , and auto generated back-end that allows you to manage completely your website.
Some cool features for Django
- Fast: Django was designed to help developers take applications from concept to completion as quickly as possible.
- Secure: Django takes security seriously and helps developers avoid common security mistakes.
- Scalable: Some of the busiest sites on the Web leverage Django’s ability to quickly and flexibly scale.
There are different websites that are using Django, for example Instagram uses Django as their back-end, also there are some more websites like Reddit, Spotify , Dropbox that are using Django.
for the installation of Django you can simple use pip install django.
2: Flask
Flask is a micro web framework that is written In python. We are saying micro framework, but it does not mean that you can not build large applications with flask, it means that flask provides a solid core with the basics services. But you can use extensions for the rest of the work. For example in flask there is no native support for database, webforms, authentications and many more but you can use extensions for this, for example for working with the forms you can use flask-wtf or for working orm model you can use sqlalchemy.
for the installation you can just use pip install flask .
simple example for flask
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
from flask import Flask app = Flask(__name__) @app.route('/') def index(): return "Hello World" if __name__ == "__main__": app.run(debug=True) |
3: CherryPy
Cherrypy is a pythonic, object oriented web framework, CherryPy allows developers to build web applications in much the same way they would build any other object-oriented Python program. This results in smaller source code developed in less time. And also . CherryPy is now more than ten years old and it is has proven to be very fast and stable . cherrypy is being used in production by many sites. According to their documentation CherryPy is used by Netflix . so Netflix uses CherryPy as a building block in their infrastructure: “Restful APIs to large applications with requests.
Some cool features for the cherrypy
- Easily runs on multiple http servers
- It has a powerful configuration system
- Also it has a flexible plugin system
- It has Built-in tools for caching, encoding, sessions, authentication, static content, and many more.
for the installation you can just use pip install cherrypy
basic example for cherrypy web framework
1 2 3 4 5 6 7 8 9 10 11 12 |
import cherrypy class MyApp(): @cherrypy.expose def index(self): return "Hello CherryPy" cherrypy.quickstart(MyApp()) |
4: Bottle
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.
Some cool features for the bottle
- Routing: Requests to function-call mapping with support for clean and dynamic URLs.
- Templates: Fast and pythonic built-in template engine and support for mako, jinja2 and cheetah templates.
- Utilities: Convenient access to form data, file uploads, cookies, headers and other HTTP-related metadata.
- Server: Built-in HTTP development server and support for paste, fapws3, bjoern, gae, cherrypy or any other WSGI capable HTTP server.
for the installation you can use pip install bottle
basic example for bottle
1 2 3 4 5 6 7 8 9 10 11 12 |
from bottle import route, run @route('/') def Index(): return "Hello Bottle Application" run(host='localhost', port=8080, debug=True) |
5: Pyramid
The Pyramid is also an open-source Python-based web development framework. Its main goal is to do as much as possible with minimum complexity. If you look at Megaframeworks, make decisions for you, but if you don’t fit their viewpoint, you end up struggling with their choices. On the other hand, Microframeworks force no decisions, making it easy to start. But as your application grows, you’re on your own. The most striking feature of the Pyramid is its ability to work well with both small and large applications.
for the installation you can use pip install pyramid
basic example for pyramid web framework
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
from wsgiref.simple_server import make_server from pyramid.config import Configurator from pyramid.response import Response def hello_world(request): return Response('Hello Pyramid Application!') if __name__ == '__main__': with Configurator() as config: config.add_route('hello', '/') config.add_view(hello_world, route_name='hello') app = config.make_wsgi_app() server = make_server('localhost', 8080, app) server.serve_forever() |
Also you can watch the complete video for Python Top 5 Web Frameworks
Subscribe and Get Free Video Courses & Articles in your Email