Getting started with the Dapr Python gRPC service extension

The Dapr Python SDK provides a built in gRPC server extension module, , for creating Dapr services.

You can download and install the Dapr gRPC server extension module with:

Note

  1. The development package will contain features and behavior that will be compatible with the pre-release version of the Dapr runtime. Make sure to uninstall any stable versions of the Python SDK extension before installing the dapr-dev package.

The InvokeMethodReqest and InvokeMethodResponse objects can be used to handle incoming requests.

A simple service that will listen and respond to requests will look like:

  1. app = App()
  2. @app.method(name='my-method')
  3. def mymethod(request: InvokeMethodRequest) -> InvokeMethodResponse:
  4. print(request.metadata, flush=True)
  5. print(request.text(), flush=True)
  6. return InvokeMethodResponse(b'INVOKE_RECEIVED', "text/plain; charset=UTF-8")

A full sample can be found here.

  1. from dapr.ext.grpc import App, BindingRequest
  2. app = App()
  3. @app.binding('kafkaBinding')
  4. def binding(request: BindingRequest):
  5. print(request.text(), flush=True)
  6. app.run(50051)

A full sample can be found .