sanic框架了解

最近在工作中需要用到sanic框架

Sanic是什么?

话不多说先给一个官方的解释

Sanic is a Python 3.6+ web server and web framework that’s written to go fast. It allows the usage of the async/await syntax added in Python 3.5, which makes your code non-blocking and speedy.

The goal of the project is to provide a simple way to get up and running a highly performant HTTP server that is easy to build, to expand, and ultimately to scale.

Sanic是python3.6以上支持async和await语法的web符合和web框架,其目的旨在提供一个建档的方法构建和运行高性能的http服务

从这段描述可以提取几个关键字,异步,高性能,易于构建扩展。是不是你想要的优点它全都有,就冲着这几个特性,那也得学习下。

为什么要学Sanic?

其实官方已经给了很好的解释,优点多多,不学是不是有点太可惜了,哈哈,我已经磨刀霍霍,准备上手了。

来看一下官方给的demo,是不是超级简单,8行代码就可以启动一个服务,岂不妙哉。

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)
1234567891011

怎么学Sanic?

1、官方文档
2、当然是其他人写的博客咯,遇到问题查查就出来了
3、源代码
通过这三个途径,然后勤学苦练,有朝一日,必有所成。

那么话不多说,赶紧操练起来

# 注意python应该是3.6+,最好是3.6.8以上的版本为好,
# 不知道怎么更新python3的,请移步百度
pip install sanic
123
posted @ 2022-09-23 12:25  hai起奈  阅读(422)  评论(0编辑  收藏  举报