5.4 KiB
sidebar_position | description |
---|---|
1 | nonebot.drivers.fastapi 模块 |
nonebot.drivers.fastapi
FastAPI 驱动适配
:::tip 提示 本驱动仅支持服务端连接 :::
class Config(_env_file='<object object>', _env_file_encoding=None, _env_nested_delimiter=None, _secrets_dir=None, *, fastapi_openapi_url=None, fastapi_docs_url=None, fastapi_redoc_url=None, fastapi_include_adapter_schema=True, fastapi_reload=False, fastapi_reload_dirs=None, fastapi_reload_delay=0.25, fastapi_reload_includes=None, fastapi_reload_excludes=None)
-
说明
FastAPI 驱动框架设置,详情参考 FastAPI 文档
-
参数
-
_env_file
(str | os.PathLike | NoneType) -
_env_file_encoding
(str | None) -
_env_nested_delimiter
(str | None) -
_secrets_dir
(str | os.PathLike | NoneType) -
fastapi_openapi_url
(str) -
fastapi_docs_url
(str) -
fastapi_redoc_url
(str) -
fastapi_include_adapter_schema
(bool) -
fastapi_reload
(bool) -
fastapi_reload_dirs
(list[str]) -
fastapi_reload_delay
(float) -
fastapi_reload_includes
(list[str]) -
fastapi_reload_excludes
(list[str])
-
class-var fastapi_openapi_url
-
类型: str | None
-
说明:
openapi.json
地址,默认为None
即关闭
class-var fastapi_docs_url
-
类型: str | None
-
说明:
swagger
地址,默认为None
即关闭
class-var fastapi_redoc_url
-
类型: str | None
-
说明:
redoc
地址,默认为None
即关闭
class-var fastapi_include_adapter_schema
-
类型: bool
-
说明: 是否包含适配器路由的 schema,默认为
True
class-var fastapi_reload
-
类型: bool
-
说明: 开启/关闭冷重载
class-var fastapi_reload_dirs
-
类型: list[str] | None
-
说明: 重载监控文件夹列表,默认为 uvicorn 默认值
class-var fastapi_reload_delay
-
类型: float
-
说明: 重载延迟,默认为 uvicorn 默认值
class-var fastapi_reload_includes
-
类型: list[str] | None
-
说明: 要监听的文件列表,支持 glob pattern,默认为 uvicorn 默认值
class-var fastapi_reload_excludes
-
类型: list[str] | None
-
说明: 不要监听的文件列表,支持 glob pattern,默认为 uvicorn 默认值
class Driver(env, config)
property asgi
-
类型: fastapi.applications.FastAPI
-
说明:
FastAPI APP
对象
property logger
-
类型: logging.Logger
-
说明: fastapi 使用的 logger
property server_app
-
类型: fastapi.applications.FastAPI
-
说明:
FastAPI APP
对象
property type
-
类型: str
-
说明: 驱动名称:
fastapi
method on_shutdown(self, func)
-
说明
参考文档:
Events <https://fastapi.tiangolo.com/advanced/events/#shutdown-event>
_ -
参数
func
(Callable)
-
返回
- Callable
method on_startup(self, func)
-
说明
参考文档:
Events <https://fastapi.tiangolo.com/advanced/events/#startup-event>
_ -
参数
func
(Callable)
-
返回
- Callable
method run(self, host=None, port=None, *, app=None, **kwargs)
-
说明
使用
uvicorn
启动 FastAPI -
参数
-
host
(str | None) -
port
(int | None) -
app
(str | None) -
**kwargs
-
-
返回
- Unknown
method setup_http_server(self, setup)
-
参数
setup
(nonebot.internal.driver.model.HTTPServerSetup)
-
返回
- Unknown
method setup_websocket_server(self, setup)
-
参数
setup
(nonebot.internal.driver.model.WebSocketServerSetup)
-
返回
- None
class FastAPIWebSocket(*, request, websocket)
-
说明
FastAPI WebSocket Wrapper
-
参数
-
request
(nonebot.internal.driver.model.Request) -
websocket
(starlette.websockets.WebSocket)
-
property closed
- 类型: bool
async method accept(self)
-
返回
- None
async method close(self, code=1000, reason='')
-
参数
-
code
(int) -
reason
(str)
-
-
返回
- None
async method receive(self)
-
返回
- str | bytes
async method receive_bytes(self)
-
返回
- bytes
async method receive_text(self)
-
返回
- str
async method send_bytes(self, data)
-
参数
data
(bytes)
-
返回
- None
async method send_text(self, data)
-
参数
data
(str)
-
返回
- None