异步Python框架有哪些
这篇文章主要介绍了异步Python框架有哪些,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
创新互联主营尼勒克网站建设的网络公司,主营网站建设方案,app开发定制,尼勒克h5小程序设计搭建,尼勒克网站营销推广欢迎尼勒克等地区企业咨询
1、Tornado

协同程序和其他原语(tornado.gen,tornado.locks,tornado.queues等) 网络模块(tornado.ioloop,tornado.iostream) 异步服务器和客户端(tornado.httpserver,httpclient,等)
通过这些模块,Tornado 构建了自己的异步Web框架模块。
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
def make_app():
return tornado.web.Application([
(r"/", MainHandler),
])
if __name__ == "__main__":
app = make_app()
app.listen(8888)
tornado.ioloop.IOLoop.current().start()
2、 Snaic

async
关键字之外,语法上和 flask 基于没差别。
from sanic import Sanic
from sanic.response import json
app = Sanic()
@app.route("/")
async def test(request):
return json({"hello": "world"})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)
3、Vibora

Vibora声称比其它框架快几倍,比竞争对手Sanic还快两倍多。 当然,这个基准测试要持怀疑态度。
from vibora import Vibora, JsonResponse
app = Vibora()
@app.route('/')
async def home():
return JsonResponse({'hello': 'world'})
if __name__ == '__main__':
app.run(host="0.0.0.0", port=8000)
4、Quart

from quart import Quart
app = Quart(__name__)
@app.route('/')
async def hello():
return 'hello'
app.run()
5、FastAPI

rom fastapi import FastAPI
app = FastAPI()
@app.get("/users/me")
async def read_user_me():
return {"user_id": "the current user"}
@app.get("/users/{user_id}")
async def read_user(user_id: str):
return {"user_id": user_id}
感谢你能够认真阅读完这篇文章,希望小编分享的“异步Python框架有哪些”这篇文章对大家有帮助,同时也希望大家多多支持创新互联,关注创新互联行业资讯频道,更多相关知识等着你来学习!
本文题目:异步Python框架有哪些
分享路径:http://pwwzsj.com/article/jjjphg.html