The documentation you are viewing is for Dapr v1.7 which is an older version of Dapr. For up-to-date documentation, see the latest version.
Dapr Python SDK 与 Flask 集成
如何创建基于 Python FastAPI 的 Dapr 虚拟 actors
Dapr Python SDK 使用 flask-dapr
模块提供与Flask 的集成
安装
你可以通过下面的方式下载和安装 Dapr Flask 扩展模块:
pip install flask-dapr
Note
开发包包含的功能和行为将兼容此前发行的 Dapr 运行时。 在安装 dapr-dev 包之前,请务必卸载以前任意稳定版本的 dapr-ext-fastapi 的 Python SDK 扩展包。
pip install flask-dapr-dev
Example
from flask import Flask
from flask_dapr.actor import DaprActor
from dapr.conf import settings
from demo_actor import DemoActor
app = Flask(f'{DemoActor.__name__}Service')
# Enable DaprActor Flask extension
actor = DaprActor(app)
# Register DemoActor
actor.register_actor(DemoActor)
# Setup method route
@app.route('/GetMyData', methods=['GET'])
def get_my_data():
return {'message': 'myData'}, 200
# Run application
if __name__ == '__main__':
app.run(port=settings.HTTP_APP_PORT)
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.