From a29d743347870cc173de6c0ab50a4d410ffdafa5 Mon Sep 17 00:00:00 2001 From: limeng Date: Tue, 18 Jan 2022 21:05:30 +0800 Subject: [PATCH] update --- docs/.vuepress/config.js | 20 ++++++++++- docs/code/django.md | 2 +- docs/code/fastapi.md | 64 +++++++++++++++++++++++++++++++++ docs/code/fastapi/begin.md | 72 ++++++++++++++++++++++++++++++++++++++ docs/code/highPython.md | 2 +- docs/code/hintapi.md | 6 ++-- docs/code/hintapi/base.md | 6 ++-- docs/code/html.md | 4 +-- docs/code/java.md | 2 +- docs/code/kotlin.md | 2 +- docs/code/linux.md | 2 +- docs/code/python.md | 2 +- docs/code/vue.md | 2 +- 13 files changed, 170 insertions(+), 16 deletions(-) create mode 100644 docs/code/fastapi.md create mode 100644 docs/code/fastapi/begin.md diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index ccd3b45..abff9fb 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -34,6 +34,8 @@ module.exports = { lineNumbers: true, }, themeConfig: { + mode: 'light', // 默认 auto,auto 跟随系统,dark 暗色模式,light 亮色模式 + modePicker: true, // 默认 true,false 不显示模式调节按钮,true 则显示 nav: [ {text: '主页', link: '/', icon: 'reco-home'}, {text: '测试相关', icon: 'reco-coding', @@ -48,7 +50,8 @@ module.exports = { items:[ {text:'基础 | Python', link: '/code/python'}, {text:'进阶 | Python', link: '/code/highPython'}, - {text:'框架 | Hintapi', link: '/code/hintapi'}, + {text:'框架 | Hint api', link: '/code/hintapi'}, + {text:'框架 | Fast api', link: '/code/fastapi'}, // {text:'框架 | Indexpy', link: '/code/indexpy'}, // {text:'插件 | DjangoSimpleAPI', link: '/code/DjangoSimpleAPI'}, {text:'框架 | Django', link: '/code/django'}, @@ -95,6 +98,11 @@ module.exports = { { icon: 'reco-bilibili', link: 'https://space.bilibili.com/2379690' }, ] }, + valineConfig: { + appId: 'NWL53SYiGO5DTWB8dYSaP4OT-gzGzoHsz',// your appId + appKey: 'fYakVEi4qRJBEuUL4GRmiTMQ', // your appKey + }, + isShowComments: true, logo: '/logo.png', authorAvatar: '/logo.png', search: true, @@ -251,6 +259,16 @@ module.exports = { ] }, ], + '/code/fastapi': [ + { + title: 'FastApi 基础篇', // 必要的 + collapsable: false, // 可选的, 默认值是 true, + sidebarDepth: 2, // 可选的, 默认值是 1 + children: [ + '/code/fastapi/begin', + ] + }, + ], '/code/vue': [ { title: 'Vue 相关', // 必要的 diff --git a/docs/code/django.md b/docs/code/django.md index 9627ee8..a74234e 100644 --- a/docs/code/django.md +++ b/docs/code/django.md @@ -1,6 +1,6 @@ --- title: Django篇 -date: 2015-04-23 +date: 2022-01-03 categories: Django author: Anges黎梦 tags: diff --git a/docs/code/fastapi.md b/docs/code/fastapi.md new file mode 100644 index 0000000..af64c11 --- /dev/null +++ b/docs/code/fastapi.md @@ -0,0 +1,64 @@ +--- +title: Fast Api +date: 2022-01-03 +categories: Fast Api +author: Anges黎梦 +tags: +- Fast Api +--- + +[comment]: <> (![](https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png)) + +## 框架介绍 + +**FastAPI 框架,高性能,易于学习,高效编码,生产需谨慎** + +--- + +官方文档: [https://fastapi.tiangolo.com](https://fastapi.tiangolo.com) + +源码: [https://github.com/tiangolo/fastapi](https://github.com/tiangolo/fastapi) + +--- + +FastAPI 是一个用于构建 API 的现代、快速(高性能)的 web 框架,使用 Python 3.6+ 并基于标准的 Python 类型提示。 + +**关键特性:** + +- 快速:可与 NodeJS 和 Go 比肩的极高性能(归功于 Starlette 和 Pydantic)。最快的 Python web 框架之一。 + +- 高效编码:提高功能开发速度约 200% 至 300%。* + +- 更少 bug:减少约 40% 的人为(开发者)导致错误。* + +- 智能:极佳的编辑器支持。处处皆可自动补全,减少调试时间。 + +- 简单:设计的易于使用和学习,阅读文档的时间更短。 + +- 简短:使代码重复最小化。通过不同的参数声明实现丰富功能。bug 更少。 + +- 健壮:生产可用级别的代码。还有自动生成的交互式文档。 + +- 标准化:基于(并完全兼容)API 的相关开放标准:OpenAPI (以前被称为 Swagger) 和 JSON Schema。 + +## 框架现存问题整理 +> 来源:网络以及实际使用 + +- Python语言异步生态并不完善 +在不完善的生态下,使用异步来进行开发,就要做好解决相关问题的准备。 + +- 论fastapi的异步生态和组件库,并不像flask/django那样有丰富而稳定的生态 +- 扩展库还并不完善,很多想法都需要自己去实现 +- fastapi也不是相对稳定,还有bug和一些设计上的不方便项 +- 异步orm生态仍然是伤,不管是sqlalchemy session的依赖注入,还是用databases异步excute,总感觉哪里有些奇怪 +- 关于后台和定时任务,仍然需要等celery和apscheduler的表现 +- 很多人其实并不是很了解异步,就开始使用框架上的异步相关内容,这样其实是不好的,对后续的维护的排查,都有很大的影响 +- 中间件相关的设计略坑,尤其是涉及很多异步的对象和组件很容易造成线程锁死 +- 异步相关也有一个很大的问题,在某种特定的情况下,可以直接打爆内存使用率,也算一个严重的问题 +- Request请求上下文对象只能被消费一次也算一个使用上的问题 + +## 使用场景 + +- 商业或者大型项目暂时不要考虑使用,稳定性不足,后续维护以及问题排查比较麻烦 + +- 公司内部系统/工具使用人数较少,可以考虑使用。 diff --git a/docs/code/fastapi/begin.md b/docs/code/fastapi/begin.md new file mode 100644 index 0000000..2d6acd2 --- /dev/null +++ b/docs/code/fastapi/begin.md @@ -0,0 +1,72 @@ +--- +title: 快速开始 +date: 2022-01-18 19:21:21:46 +categories: [FastApi] +author: Anges黎梦 +tags: +- Python +- FastApi +--- + +## 环境安装 + +**FastApi**与普通的py标准库一样安装,直接使用`pip install`即可安装使用 +```shell +pip install fastapi +``` + +## 开始使用 + +### 编写一个简单的应用 +使用时,需要引入**FastAPI**的库,并创建一个`app`; + +启动时,需要使用`uvicorn`,在`main`中编写启动命令,如下: + +```Python +import uvicorn +from fastapi import FastAPI + +app = FastAPI() + + +@app.get("/") +def test(): + return "Hello World" + + +if __name__ == '__main__': + uvicorn.run(app='main:app', host="127.0.0.1", port=8000, reload=True, debug=True) +``` + +### 应用启动 +直接脚本执行即可启动应用 + +展示如下时,启动成功,访问地址`http://127.0.0.1:8000` +```shell +INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) +INFO: Started reloader process [88610] using statreload +INFO: Started server process [88612] +INFO: Waiting for application startup. +INFO: Application startup complete. +``` + +打开浏览器,即可请求已经写好的get接口 +展示如下: +![](https://limeng-blog.oss-cn-hangzhou.aliyuncs.com/fastapi/begin-1.png) + +### 接口文档 +**FastAPI**集成了`swagger`和`redoc` +启动后即可直接打开使用,无需另外配置 + +`swagger`默认地址:`http://127.0.0.1:8000/docs` + +`swagger`除了展示接口文档外,还支持接口调试,是开发者最常用的接口文档插件,非常便捷使用 + +![](https://limeng-blog.oss-cn-hangzhou.aliyuncs.com/fastapi/begin-2.png) + +`redoc`默认地址:`http://127.0.0.1:8000/redoc` + +`redoc`仅用于接口文档分类分组展示以及接口内容展示,不涉及接口调试 +所以大家在使用上可以根据自己的需求选择使用 + +![](https://limeng-blog.oss-cn-hangzhou.aliyuncs.com/fastapi/begin-3.png) diff --git a/docs/code/highPython.md b/docs/code/highPython.md index 2bf3c46..9beed2f 100644 --- a/docs/code/highPython.md +++ b/docs/code/highPython.md @@ -1,6 +1,6 @@ --- title: Python进阶篇 -date: 2015-04-23 +date: 2022-01-03 categories: Python author: Anges黎梦 tags: diff --git a/docs/code/hintapi.md b/docs/code/hintapi.md index fe1f003..4a63487 100644 --- a/docs/code/hintapi.md +++ b/docs/code/hintapi.md @@ -1,17 +1,17 @@ --- -title: Hintapi +title: Hint api date: 2022-01-08 categories: Hintapi author: Anges黎梦 tags: -- Hintapi +- Hint api --- ## Hint API > 基于 Type hint 的 Web 框架 -Hintapi 实现了 [WSGI](https://wsgi.readthedocs.io/en/latest/) 接口,并使用 Radix Tree 进行路由查找。是[最快的 Python web 框架之一](https://github.com/the-benchmarker/web-frameworks)。一切特性都服务于快速开发高性能的 Web 服务。 +Hint Api 实现了 [WSGI](https://wsgi.readthedocs.io/en/latest/) 接口,并使用 Radix Tree 进行路由查找。是[最快的 Python web 框架之一](https://github.com/the-benchmarker/web-frameworks)。一切特性都服务于快速开发高性能的 Web 服务。 官网文档:[Hint API](https://hintapi.aber.sh/stable/) diff --git a/docs/code/hintapi/base.md b/docs/code/hintapi/base.md index 2261137..8a6e268 100644 --- a/docs/code/hintapi/base.md +++ b/docs/code/hintapi/base.md @@ -1,7 +1,7 @@ --- -title: 认识 Hintapi -date: 2022-01-08 -categories: Hintapi +title: 认识 Hint api +date: 2022-01-8 +categories: Hint api author: Anges黎梦 tags: - Hintapi diff --git a/docs/code/html.md b/docs/code/html.md index 6de4258..0903b0f 100644 --- a/docs/code/html.md +++ b/docs/code/html.md @@ -1,6 +1,6 @@ --- -title: 前端篇 -date: 2015-04-23 +title: HTML基础篇 +date: 2022-01-03 categories: HTML author: Anges黎梦 tags: diff --git a/docs/code/java.md b/docs/code/java.md index 716e361..df0cf51 100644 --- a/docs/code/java.md +++ b/docs/code/java.md @@ -1,6 +1,6 @@ --- title: Java 基础篇 -date: 2015-04-23 +date: 2022-01-03 categories: Java author: Anges黎梦 tags: diff --git a/docs/code/kotlin.md b/docs/code/kotlin.md index f83f1f9..9648e7b 100644 --- a/docs/code/kotlin.md +++ b/docs/code/kotlin.md @@ -1,6 +1,6 @@ --- title: Kotlin -date: 2015-04-23 +date: 2022-01-03 categories: Kotlin author: Karl tags: diff --git a/docs/code/linux.md b/docs/code/linux.md index 705ebc9..341cbb0 100644 --- a/docs/code/linux.md +++ b/docs/code/linux.md @@ -1,6 +1,6 @@ --- title: Linux -date: 2015-04-23 +date: 2022-01-03 categories: Linux author: Anges黎梦 tags: diff --git a/docs/code/python.md b/docs/code/python.md index 366efe3..baa48e8 100644 --- a/docs/code/python.md +++ b/docs/code/python.md @@ -1,6 +1,6 @@ --- title: Python基础篇 -date: 2015-04-23 +date: 2022-01-03 categories: Python author: Anges黎梦 tags: diff --git a/docs/code/vue.md b/docs/code/vue.md index 0598c0c..c0d6e61 100644 --- a/docs/code/vue.md +++ b/docs/code/vue.md @@ -1,6 +1,6 @@ --- title: Vue 相关 -date: 2015-04-23 +date: 2022-01-03 categories: Vue author: Anges黎梦 tags: