Dapr Python SDK integration with FastAPI

How to create Dapr Python virtual actors with the FastAPI extension

The Dapr Python SDK provides integration with FastAPI using the dapr-ext-fastapi module


You can download and install the Dapr FastAPI extension module with:

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)

async def startup_event():
    # Register DemoActor
    await actor.register_actor(DemoActor)

def get_my_data():
    return "{'message': 'myData'}"