程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Python] asynchronous web framework sanic

編輯:Python

One 、 brief introduction

Sanic It's a Python 3.7+ web The server and web frame , It's written very fast . It allows the use of async/awaitPython 3.5 Syntax added in , This makes your code non blocking and fast .

sanic github project .
sanic Using document

  • The goal is :
    Provides a simple way to start and run easy to build 、 High performance for expansion and final expansion HTTP The server .

  • features
    Built in fast network server
    Production ready
    Highly scalable
    accord with ASGI
    Simple and intuitive API Design

Two 、 and Flask web The difference between frames

sanic Asynchronous Support ,flask I won't support it

3、 ... and 、 ordinary demo

from sanic import Sanic
from sanic.response import json
from sanic.exceptions import NotFound
app = Sanic(name="pyapp")
@app.route('/')
async def test(request):
return json({'hello': 'world'})
if __name__ == '__main__':
app.error_handler.add(
NotFound,
lambda r, e: sanic.response.empty(status=404)
)
app.run(host='0.0.0.0', port=8000)

Access page :
http://localhost:8000/


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved