Skip to content

Commit 6645c5a

Browse files
authored
Merge pull request #54037 from vrdmr/vameru/eventgrid-output-binding-documentation
Adding Python EventGrid output binding example.
2 parents 61d9670 + 5ed1888 commit 6645c5a

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

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

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

163209
# [Java](#tab/java)
164210

0 commit comments

Comments
 (0)