Dapr Python SDK 使用 dapr-ext-fastapi
模块与 FastAPI 集成
你可以通过下面的方式下载和安装 Dapr FastAPI 扩展模块:
pip install dapr-ext-fastapi
pip install dapr-ext-fastapi-dev
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'}"