Skip to content

Commit 5021452

Browse files
committed
Adding Python EventGrid output binding example.
1 parent 61ee2af commit 5021452

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

articles/azure-functions/functions-bindings-event-grid-output.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,51 @@ module.exports = function(context) {
158158

159159
# [Python](#tab/python)
160160

161-
The Event Grid output binding is not available for Python.
161+
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`.
162+
163+
Here's the binding data in the *function.json* file:
164+
```json
165+
{
166+
"scriptFile": "__init__.py",
167+
"bindings": [
168+
{
169+
"type": "eventGridTrigger",
170+
"name": "eventGridEvent",
171+
"direction": "in"
172+
},
173+
{
174+
"type": "eventGrid",
175+
"name": "outputEvent",
176+
"topicEndpointUri": "MyEventGridTopicUriSetting",
177+
"topicKeySetting": "MyEventGridTopicKeySetting",
178+
"direction": "out"
179+
}
180+
],
181+
"disabled": false
182+
}
183+
```
184+
185+
Here's the python sample to send a event to a custom Event Grid topic by setting the `EventGridOutputEvent`.
186+
```python
187+
import logging
188+
import azure.functions as func
189+
import datetime
190+
191+
192+
def main(eventGridEvent: func.EventGridEvent,
193+
outputEvent: func.Out[func.EventGridOutputEvent]) -> None:
194+
195+
logging.log("eventGridEvent: ", eventGridEvent)
196+
197+
outputEvent.set(
198+
func.EventGridOutputEvent(
199+
id="test-id",
200+
data={"tag1": "value1", "tag2": "value2"},
201+
subject="test-subject",
202+
event_type="test-event-1",
203+
event_time=datetime.datetime.utcnow(),
204+
data_version="1.0"))
205+
```
162206

163207
# [Java](#tab/java)
164208

0 commit comments

Comments
 (0)