In this article we are going to introduce Python Web Development Frameworks ,
so as you know Python is general purpose language, it means that there are different
sections that you can use Python, one of them is Web Development, in this article we
are going to introduce the most powerful and popular Python Web Development Frameworks.
What is 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.
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.
Installation
You can simply install django using pip
1 |
pip install django |
For creating of Django Project you can use this command.
1 |
django-admin startproject MyProject |
Now run your Project
1 |
python manage.py runserver |
This will be the result
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. bong
Installation
You can use pip for the installation
1 |
pip install flask |
Creating an example in Flask
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
from flask import Flask app = Flask(__name__) @app.route('/') def index(): return "<h1>Geekscoders.com - Flask Web Development</h1>" if __name__ == "__main__": app.run(debug=True) |
Run the example and this is the result
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.
Installation
You can install cherrypy using pip
1 |
pip install cherrypy |
Creating an example in CherryPy
1 2 3 4 5 6 7 8 9 10 11 12 |
import cherrypy class MyApp(): @cherrypy.expose def index(self): return "<h1>Geekscoders.com - CherryPy Example</h1>" cherrypy.quickstart(MyApp()) |
Run the code and this is the result
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.
Installation
You can install bottle using pip
1 |
pip install bottle |
Creating example in Bottle Python Web Development Frameworks
1 2 3 4 5 6 7 8 9 10 11 12 |
from bottle import route, run @route('/') def Index(): return "<h1>Geekscoders.com - Bottle Example<h1>" run(host='localhost', port=5050, debug=True) |
Run the code and this will be the result.
5: Pyramid
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.
Installation
1 |
pip install pyramid |
Creating an example in 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('<h1>Geekscoders.com - Pyramid Example</h1>') 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() |
Run the code and this is the example
Conclusion
All Python Web Development Frameworks are good, but in my opinion if you are planing
to build a large project than Django is the best choice, because it is a full featured web
framework, Flask is good for small projects.
Join Our Free Courses