NoneBot.drivers.fastapi 模块 | NoneBot
Description: 跨平台 Python 异步 QQ 机器人框架

# # NoneBot.drivers.fastapi 模块

## # FastAPI 驱动适配

后端使用方法请参考: FastAPI 文档
(opens new window)

## # class `Driver`

基类：`nonebot.drivers.BaseDriver`

FastAPI 驱动框架

- 上报地址

  - `/{adapter name}/`: HTTP POST 上报

  - `/{adapter name}/http/`: HTTP POST 上报

  - `/{adapter name}/ws`: WebSocket 上报

  - `/{adapter name}/ws/`: WebSocket 上报

### # property `type`

驱动名称: `fastapi`

### # property `server_app`

`FastAPI APP` 对象

### # property `asgi`

`FastAPI APP` 对象

### # property `logger`

fastapi 使用的 logger

### # `on_startup(func)`

参考文档: Events
(opens new window)

### # `on_shutdown(func)`

参考文档: Events
(opens new window)

### # `run(host=None, port=None, *, app=None, **kwargs)`

使用 `uvicorn` 启动 FastAPI

### # async `_handle_http(adapter, request, data=Body(Ellipsis))`

用于处理 HTTP 类型请求的函数

### # async `_handle_ws_reverse(adapter, websocket)`

用于处理 WebSocket 类型请求的函数

## # class `WebSocket`

基类：`nonebot.drivers.BaseWebSocket`

### # property `closed`

- 类型

  `bool`

- 说明

  连接是否已经关闭

### # async `accept()`

接受 WebSocket 连接请求

### # async `close(code=1000)`

关闭 WebSocket 连接请求

### # async `receive()`

接收一条 WebSocket 信息

### # async `send(data)`

发送一条 WebSocket 信息

Contents

- FastAPI 驱动适配
- class Driver
  - property type
  - property server_app
  - property asgi
  - property logger
  - on_startup(func)
  - on_shutdown(func)
  - run(host=None, port=None, *, app=None, **kwargs)
  - async _handle_http(adapter, request, data=Body(Ellipsis))
  - async _handle_ws_reverse(adapter, websocket)
- class WebSocket
  - property closed
  - async accept()
  - async close(code=1000)
  - async receive()
  - async send(data)