This commit is contained in:
limeng 2022-01-18 21:05:30 +08:00
parent ac861a7cb5
commit a29d743347
13 changed files with 170 additions and 16 deletions

View File

@ -34,6 +34,8 @@ module.exports = {
lineNumbers: true,
},
themeConfig: {
mode: 'light', // 默认 autoauto 跟随系统dark 暗色模式light 亮色模式
modePicker: true, // 默认 truefalse 不显示模式调节按钮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 相关', // 必要的

View File

@ -1,6 +1,6 @@
---
title: Django篇
date: 2015-04-23
date: 2022-01-03
categories: Django
author: Anges黎梦
tags:

64
docs/code/fastapi.md Normal file
View File

@ -0,0 +1,64 @@
---
title: Fast Api
date: 2022-01-03
categories: Fast Api
author: Anges黎梦
tags:
- Fast Api
---
[comment]: <> (![]&#40;https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png&#41;)
## 框架介绍
**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请求上下文对象只能被消费一次也算一个使用上的问题
## 使用场景
- 商业或者大型项目暂时不要考虑使用,稳定性不足,后续维护以及问题排查比较麻烦
- 公司内部系统/工具使用人数较少,可以考虑使用。

View File

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

View File

@ -1,6 +1,6 @@
---
title: Python进阶篇
date: 2015-04-23
date: 2022-01-03
categories: Python
author: Anges黎梦
tags:

View File

@ -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/)

View File

@ -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

View File

@ -1,6 +1,6 @@
---
title: 前端
date: 2015-04-23
title: HTML基础
date: 2022-01-03
categories: HTML
author: Anges黎梦
tags:

View File

@ -1,6 +1,6 @@
---
title: Java 基础篇
date: 2015-04-23
date: 2022-01-03
categories: Java
author: Anges黎梦
tags:

View File

@ -1,6 +1,6 @@
---
title: Kotlin
date: 2015-04-23
date: 2022-01-03
categories: Kotlin
author: Karl
tags:

View File

@ -1,6 +1,6 @@
---
title: Linux
date: 2015-04-23
date: 2022-01-03
categories: Linux
author: Anges黎梦
tags:

View File

@ -1,6 +1,6 @@
---
title: Python基础篇
date: 2015-04-23
date: 2022-01-03
categories: Python
author: Anges黎梦
tags:

View File

@ -1,6 +1,6 @@
---
title: Vue 相关
date: 2015-04-23
date: 2022-01-03
categories: Vue
author: Anges黎梦
tags: