The documentation you are viewing is for Dapr v1.8 which is an older version of Dapr. For up-to-date documentation, see the latest version.
Dapr Python SDK 与 FastAPI 集成
如何创建基于 FastAPI 扩展的Dapr Python virtual actors
Dapr Python SDK 使用 dapr-ext-fastapi
模块与 FastAPI 集成
安装
你可以通过下面的方式下载和安装 Dapr FastAPI 扩展模块:
pip install dapr-ext-fastapi
Note
开发包包含的功能和行为将兼容此前发行的 Dapr 运行时。 在安装 dapr-dev 包之前,请务必卸载以前任意稳定版本的 dapr-ext-fastapi 的 Python SDK 扩展包。
pip install dapr-ext-fastapi-dev
Example
from fastapi import FastAPI
from dapr.ext.fastapi import DaprActor
from demo_actor import DemoActor
app = FastAPI(title=f'{DemoActor.__name__}Service')
# Add Dapr Actor Extension
actor = DaprActor(app)
@app.on_event("startup")
async def startup_event():
# Register DemoActor
await actor.register_actor(DemoActor)
@app.get("/GetMyData")
def get_my_data():
return "{'message': 'myData'}"
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.