From 5021452a98fc973fad12804328710f497cb0708f Mon Sep 17 00:00:00 2001 From: "Varad Meru [gmail]" Date: Mon, 4 May 2020 16:46:54 -0700 Subject: [PATCH 1/2] Adding Python EventGrid output binding example. --- .../functions-bindings-event-grid-output.md | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/articles/azure-functions/functions-bindings-event-grid-output.md b/articles/azure-functions/functions-bindings-event-grid-output.md index 05f25dc0a8c04..671fb45977db7 100644 --- a/articles/azure-functions/functions-bindings-event-grid-output.md +++ b/articles/azure-functions/functions-bindings-event-grid-output.md @@ -158,7 +158,51 @@ module.exports = function(context) { # [Python](#tab/python) -The Event Grid output binding is not available for Python. +The following example shows a trigger binding in a *function.json* file and a [Python function](functions-reference-python.md) that uses the binding. It then sends in an event to the custom event grid topic, as specified by the `topicEndpointUri`. + +Here's the binding data in the *function.json* file: +```json +{ + "scriptFile": "__init__.py", + "bindings": [ + { + "type": "eventGridTrigger", + "name": "eventGridEvent", + "direction": "in" + }, + { + "type": "eventGrid", + "name": "outputEvent", + "topicEndpointUri": "MyEventGridTopicUriSetting", + "topicKeySetting": "MyEventGridTopicKeySetting", + "direction": "out" + } + ], + "disabled": false +} +``` + +Here's the python sample to send a event to a custom Event Grid topic by setting the `EventGridOutputEvent`. +```python +import logging +import azure.functions as func +import datetime + + +def main(eventGridEvent: func.EventGridEvent, + outputEvent: func.Out[func.EventGridOutputEvent]) -> None: + + logging.log("eventGridEvent: ", eventGridEvent) + + outputEvent.set( + func.EventGridOutputEvent( + id="test-id", + data={"tag1": "value1", "tag2": "value2"}, + subject="test-subject", + event_type="test-event-1", + event_time=datetime.datetime.utcnow(), + data_version="1.0")) +``` # [Java](#tab/java) From 5ed18880d644b839b57cec20eddf655f1aaa4470 Mon Sep 17 00:00:00 2001 From: Kristine Toliver Date: Tue, 19 May 2020 09:17:16 -0700 Subject: [PATCH 2/2] public repo edit --- .../azure-functions/functions-bindings-event-grid-output.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/articles/azure-functions/functions-bindings-event-grid-output.md b/articles/azure-functions/functions-bindings-event-grid-output.md index 671fb45977db7..59435defa7a82 100644 --- a/articles/azure-functions/functions-bindings-event-grid-output.md +++ b/articles/azure-functions/functions-bindings-event-grid-output.md @@ -158,9 +158,10 @@ module.exports = function(context) { # [Python](#tab/python) -The following example shows a trigger binding in a *function.json* file and a [Python function](functions-reference-python.md) that uses the binding. It then sends in an event to the custom event grid topic, as specified by the `topicEndpointUri`. +The following example shows a trigger binding in a *function.json* file and a [Python function](functions-reference-python.md) that uses the binding. It then sends in an event to the custom Event Grid topic, as specified by the `topicEndpointUri`. Here's the binding data in the *function.json* file: + ```json { "scriptFile": "__init__.py", @@ -182,7 +183,8 @@ Here's the binding data in the *function.json* file: } ``` -Here's the python sample to send a event to a custom Event Grid topic by setting the `EventGridOutputEvent`. +Here's the Python sample to send a event to a custom Event Grid topic by setting the `EventGridOutputEvent`: + ```python import logging import azure.functions as func