Nowadays, Python becomes one of the most popular language for Web development. There are many famous websites such as Instagram, Disqus and so on using it. This post will talk about the backend architecture of a Python web application.
There are three common components (layers) in the backend side of a Python web application:
Their relationships are as follows:
First of all, we need a web server to receive HTTP requests and send back responses containing status code and other contents such as HTML, XML or JSON as well.
There are lots of web server implementations suitable for Python web service. Considering ease of use, stability, security, market share and other issues, Apache and Nginx are most popular. The Apache HTTP Server has been the most commonly deployed web server on the Internet for 20+ years. Nginx is the second most commonly used server for the top 100,000 websites.
A traditional web server does not understand or have any way to run Python applications. Therefore, the Python community came up with WSGI as a standard interface that modules and containers could implement. WSGI is now the commonly accepted approach for running Python web applications on web servers.
Because WSGI is just a standard interface, there are also different implementations of WSGI server base on that to help Python applications communicate with web servers. Gunicorn and uWSGI are two most popular WSGI servers.
There are two main benefits from a good WSGI server:
To summary, WSGI server takes care of everything which happens in-between the web server and the web application. This way, when coding up a Python application we don’t need to find solutions for:
Python’s web application framework makes the process of app development much easier. A framework implements common issues for a web application (such as template system, ORM (Object Relational Mapping) systems, user authentication, content administration, site maps, RSS feeds, and many more tasks) and we just need to develop our commercial logic upon it.
There are also many application frameworks for Python web development. Such as Django, Flask and Tornado.
More and more websites select Python for Web development. The backend structure of a Python Web application is clear and low coupling and development in Python can save developers lots of time.
Thanks for reading. If you like it, please follow my publication TechToFreedom, where you can enjoy other Python tutorials and topics about programming, technology and investment.