preface

Toss and turn, can’t sleep! Once something is growing in your brain and you don’t act on it, you find yourself feeling frustrated over time. So I decided to write down some of the knowledge I had used, purely as my own study notes.

For web development, in fact, I was a little white, from android to the front-end (pure white) to the back end, after some big and small project experience, you will have a belongs to own the system of knowledge tree, remember before I take my manager Daniel said, the output is the best way of learning, has been teaching for learning, and can promote their thinking. So I still hope I can insist on sorting out some knowledge points in the past.

The initial learning of the web back end was led by Daniel’s supervisor, and you can read his articles on this blog if you need to. Word-wrap: break-word! Important; “>🔥

Daniel address official blog address www.cnblogs.com/EmptyFS/ view.

Forced to force out

About myself: pure is a handyman, seems to have done any work, moving bricks in a small company for a long time, seems to know some things, so some places in the blog estimate mistakes, but also ask you heroes, a lot of excuse! This series of text is not an article, but like my personal daily development notes, it is inevitable that there are some personal thoughts, if you have any questions, I hope you can kindly forgive me.

About Python Web development

The PYTHON WEB is currently mostly used in the industry as a framework for processes: Flask, Django, Tornado, etc., basically pursue the web framework around the following points. Sometimes we choose the framework according to the team and business. In some cases, you can even choose Node. JS or Go for high performance. There are several excellent mining machines in these languages, such as EGG. JS and GIN or Beego for GO language.

  • Frame difficulty
  • Framework security
  • The framework is easy to maintain
  • Frame difficulty
  • Processing ability, speed

In essence, all of our frameworks are the same, and a Web framework usually revolves around:

  • The router processes the REQUESTED URL
  • Model Data model
  • Controller Data business logic processing

Another option to look at is our business profile: (Generally we certainly do not deal with CPU-intensive tasks in our Web framework) :

  • CPU intensive tasks
  • IO intensive task

Even with new features introduced since PY3, such as async/await coroutines, we can divide Web frameworks into synchronous and asynchronous frameworks. In terms of asynchrony and synchronization, we can roughly divide into WSGI and ASGI.

So what are WSGI and ASGI? Which frameworks are ASGI? Which ones are WSGI? I’m going to briefly summarize here, and I’m going to take notes on my next use of the asynchronous framework.

What is the WSGI

To understand what WSGI is, first we need to understand what CGI is. The following is an excerpt from Baidu Baike:

The Python Web Server Gateway Interface (WSGI for short) is a simple and generic Interface between a Web Server and a Web application or framework defined for the Python language

WSGI is divided into two parts: a “server” or “gateway” and an “application” or “application framework.” When a WSGI request is processed, the server provides the application with environment information and a Callback Function. When the application completes processing the request, it sends the results back to the server through the aforementioned callback function. So-called WSGI middleware implements both sides of the API and therefore acts as a mediator between a WSGI server and a WSGI application: middleware acts as an application from a Web server perspective, while middleware acts as a server from an application perspective. The “middleware” component performs functions such as overriding environment variables and routing request messages to different application objects based on the target URL. Allows multiple applications or application frameworks to run simultaneously in one process. Load balancing and remote processing by forwarding request and response messages over the network. Post-processing of content, such as applying XSLT stylesheets.

Python Paste – WSGI underlying toolset. Includes multithreading, SSL and authentication libraries based on Cookies, sessions, etc. You can easily build your own Web framework using Paste. WSGI:Python Web Server Gateway Interface v1.0 is defined in PEP3333 (the goal of PEP3333 is to create a simple, universal Interface between a Server and a Web framework) WSGI is an interface between a Python application or framework and a Web server. WSGI is widely accepted and has largely achieved its portability goals. As mentioned repeatedly in Guido’s Blog, Personally, WSGI is the most Pythonic equivalent of the Java “servlet” API for Python Web. [3]

What is a ASGI

ASGI is an asynchronous gateway protocol interface. It is a standard interface before network protocol services and PYTHON applications. It can process HTTP, HTTP2, and WebSocket protocols.

ASGI helps to implement a Python Web framework ecosystem that achieves high throughput in the context of some frameworks that implement IO binding. In terms of performance, Node is comparable to Go, but Go is certainly faster.

ASGI also provides support for HTTP / 2 and WebSockets, which WSGI cannot handle.

What are the frameworks supporting the WSGI protocol specification?

  • flask
  • Django
  • bottle
  • web.py
  • CherryPy
  • web2py
  • Tornado
  • Gunicorn
  • falcon

What are the frameworks supporting the ASGI protocol specification?

  • Uvicorn
  • APIStar
  • Sanic
  • Fastapi
  • Quart (similar to flask asynchronous framework)

Synchronization and asynchrony in Python Web development

There has always been a controversy over the issue of synchronization and asynchrony. So what is synchronization and what is synchronization? We also need to ask what problems we encounter in some frameworks, such as what is blocking and non-blocking, what is concurrency and parallelism and other issues to understand:

I will not elaborate too much here, this 🔥 code nongfuge has detailed answers to questions.

About synchronization frame -Bottle

Maybe you must have a bunch of questions why you still use this niche framework. In fact, I think for the framework debate, I personally think that whichever goes well, I will use whichever. Generally speaking, the performance gap between them is not very big before, and I personally think it is meaningless to be limited to the framework debate. Flask, Bottle, Django, we are essentially the same, all born for business development. What is good or bad, after using lengnuanzizhi!

I used this framework because it was the first time I came into contact with the back end, and my supervisor used this framework to deal with our production environment. Naturally, it became one of the first frameworks I started with.

END

Ok, everybody, the above is about the introduction to bottle, which is not nutritious. It is mainly paving the way for the beginning of the next few articles.

Let students | article [original] [reproduced please contact my] | QQ: 308711822