How to receive MQTT payload in JSON in Azure Function subscribed to Event Grid using Python?

Pawel Czop 20 Reputation points
2025-04-24T21:45:13.0266667+00:00

I configured Azure Event grid with namespace and enabled MQTT broker.

I want to receive the MQTT messages including JSON payload using Azure Function App in Python language.

The exemplary code provided in the EventGrid trigger example returns topic of the message in "subject" and message Id in "id", but the rest of the fields including "data" are null for EventGridEvent instance passed to function.

However, when I run C# example:

https://learn.microsoft.com/en-us/azure/event-grid/mqtt-routing-to-azure-functions-portal#create-an-azure-function-using-event-grid-trigger

I can also read data properly

Please provide a guidance how to read the JSON payload from published MQTT messages from EventGridEvent object instance in Python?

Azure Event Grid
Azure Event Grid
An Azure event routing service designed for high availability, consistent performance, and dynamic scale.
439 questions
{count} votes

Accepted answer
  1. LeelaRajeshSayana-MSFT 17,676 Reputation points
    2025-04-26T10:09:42.43+00:00

    @Pawel Czop The current version of Azure Function Python package does not have an implementation to handle events in the format of CloudEvent You can find the supported Python classes for the Azure functions in Event Grid from the downloaded package azure_functions-1.23.0\azure\functions\_eventgrid.py file. Python version of Azure function only supports EventGridEvent.

    The C# code you have referenced does support this CloudEvent format which is why the data from the routing is successful. Since Event Grid Namespace routing to a custom topic only works with Cloud Event Schema type, I would say this is a limitation with Python code.

    I will take this limitation to the product team and see if this gets addressed in the future versions.


    If this answers your query, please do click Accept Answer and Yes, as it might be beneficial to other community members reading this thread. If you have any further query, do let us know. Thank you

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.