Skip to content

Commit 8a3de17

Browse files
authored
Updating example variables and linebreaks
1 parent 1d074b5 commit 8a3de17

File tree

1 file changed

+80
-47
lines changed

1 file changed

+80
-47
lines changed

articles/azure-functions/functions-bindings-triggers-python.md

Lines changed: 80 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ The following code snippet defines a function triggered from Azure Blob Storage:
3333
```python
3434
import logging
3535
import azure.functions as func
36+
3637
app = func.FunctionApp()
38+
3739
@app.function_name(name="BlobTrigger1")
38-
@app.blob_trigger(arg_name="myblob", path="samples-workitems/{name}",
39-
connection="AzureWebJobsStorage")
40+
@app.blob_trigger(arg_name="myblob",
41+
path="PATH/TO/BLOB",
42+
connection="CONNECTION_SETTING")
4043
def test_function(myblob: func.InputStream):
4144
logging.info(f"Python blob trigger function processed blob \n"
4245
f"Name: {myblob.name}\n"
@@ -48,12 +51,14 @@ def test_function(myblob: func.InputStream):
4851
```python
4952
import logging
5053
import azure.functions as func
54+
5155
app = func.FunctionApp()
56+
5257
@app.function_name(name="BlobInput1")
5358
@app.route(route="file")
5459
@app.blob_input(arg_name="inputblob",
55-
path="sample-workitems/{name}",
56-
connection="AzureWebJobsStorage")
60+
path="PATH/TO/BLOB",
61+
connection="CONNECTION_SETTING")
5762
def test(req: func.HttpRequest, inputblob: bytes) -> func.HttpResponse:
5863
logging.info(f'Python Queue trigger function processed {len(inputblob)} bytes')
5964
return inputblob
@@ -64,15 +69,17 @@ def test(req: func.HttpRequest, inputblob: bytes) -> func.HttpResponse:
6469
```python
6570
import logging
6671
import azure.functions as func
72+
6773
app = func.FunctionApp()
74+
6875
@app.function_name(name="BlobOutput1")
6976
@app.route(route="file")
7077
@app.blob_input(arg_name="inputblob",
71-
path="sample-workitems/test.txt",
72-
connection="AzureWebJobsStorage")
78+
path="PATH/TO/BLOB",
79+
connection="CONNECTION_SETTING")
7380
@app.blob_output(arg_name="outputblob",
74-
path="newblob/test.txt",
75-
connection="AzureWebJobsStorage")
81+
path="PATH/TO/BLOB",
82+
connection="CONNECTION_SETTING")
7683
def main(req: func.HttpRequest, inputblob: str, outputblob: func.Out[str]):
7784
logging.info(f'Python Queue trigger function processed {len(inputblob)} bytes')
7885
outputblob.set(inputblob)
@@ -86,9 +93,14 @@ The following code snippet defines a function triggered from an Azure Cosmos DB
8693
```python
8794
import logging
8895
import azure.functions as func
96+
8997
app = func.FunctionApp()
98+
9099
@app.function_name(name="CosmosDBTrigger1")
91-
@app.cosmos_db_trigger(arg_name="documents", database_name="<DB_NAME>", collection_name="<COLLECTION_NAME>", connection_string_setting=""AzureWebJobsStorage"",
100+
@app.cosmos_db_trigger(arg_name="documents",
101+
database_name="DB_NAME",
102+
collection_name="COLLECTION_NAME",
103+
connection_string_setting="CONNECTION_SETTING",
92104
lease_collection_name="leases", create_lease_collection_if_not_exists="true")
93105
def test_function(documents: func.DocumentList) -> str:
94106
if documents:
@@ -100,12 +112,14 @@ def test_function(documents: func.DocumentList) -> str:
100112
```python
101113
import logging
102114
import azure.functions as func
115+
103116
app = func.FunctionApp()
117+
104118
@app.route()
105-
@app.cosmos_db_input(
106-
arg_name="documents", database_name="<DB_NAME>",
107-
collection_name="<COLLECTION_NAME>",
108-
connection_string_setting="CONNECTION_SETTING")
119+
@app.cosmos_db_input(arg_name="documents",
120+
database_name="DB_NAME",
121+
collection_name="COLLECTION_NAME",
122+
connection_string_setting="CONNECTION_SETTING")
109123
def cosmosdb_input(req: func.HttpRequest, documents: func.DocumentList) -> str:
110124
return func.HttpResponse(documents[0].to_json())
111125
```
@@ -115,12 +129,15 @@ def cosmosdb_input(req: func.HttpRequest, documents: func.DocumentList) -> str:
115129
```python
116130
import logging
117131
import azure.functions as func
132+
133+
app = func.FunctionApp()
134+
118135
@app.route()
119-
@app.cosmos_db_output(
120-
arg_name="documents", database_name="<DB_NAME>",
121-
collection_name="<COLLECTION_NAME>",
122-
create_if_not_exists=True,
123-
connection_string_setting="CONNECTION_SETTING")
136+
@app.cosmos_db_output(arg_name="documents",
137+
database_name="DB_NAME",
138+
collection_name="COLLECTION_NAME",
139+
create_if_not_exists=True,
140+
connection_string_setting="CONNECTION_SETTING")
124141
def main(req: func.HttpRequest, documents: func.Out[func.Document]) -> func.HttpResponse:
125142
request_body = req.get_body()
126143
documents.set(func.Document.from_json(request_body))
@@ -134,10 +151,13 @@ The following code snippet defines a function triggered from an event hub instan
134151
```python
135152
import logging
136153
import azure.functions as func
154+
137155
app = func.FunctionApp()
156+
138157
@app.function_name(name="EventHubTrigger1")
139-
@app.event_hub_message_trigger(arg_name="myhub", event_hub_name="samples-workitems",
140-
connection=""CONNECTION_SETTING"")
158+
@app.event_hub_message_trigger(arg_name="myhub",
159+
event_hub_name="EVENT_HUB_NAME",
160+
connection="CONNECTION_SETTING")
141161
def test_function(myhub: func.EventHubEvent):
142162
logging.info('Python EventHub trigger processed an event: %s',
143163
myhub.get_body().decode('utf-8'))
@@ -148,11 +168,13 @@ def test_function(myhub: func.EventHubEvent):
148168
```python
149169
import logging
150170
import azure.functions as func
171+
151172
app = func.FunctionApp()
173+
152174
@app.function_name(name="eventhub_output")
153175
@app.route(route="eventhub_output")
154176
@app.event_hub_output(arg_name="event",
155-
event_hub_name="samples-workitems",
177+
event_hub_name="EVENT_HUB_NAME",
156178
connection="CONNECTION_SETTING")
157179
def eventhub_output(req: func.HttpRequest, event: func.Out[str]):
158180
body = req.get_body()
@@ -170,25 +192,16 @@ The following code snippet defines an HTTP triggered function:
170192
```python
171193
import azure.functions as func
172194
import logging
195+
173196
app = func.FunctionApp(auth_level=func.AuthLevel.ANONYMOUS)
197+
174198
@app.function_name(name="HttpTrigger1")
175199
@app.route(route="hello")
176200
def test_function(req: func.HttpRequest) -> func.HttpResponse:
177-
logging.info('Python HTTP trigger function processed a request.')
178-
name = req.params.get('name')
179-
if not name:
180-
try:
181-
req_body = req.get_json()
182-
except ValueError:
183-
pass
184-
else:
185-
name = req_body.get('name')
186-
if name:
187-
return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
188-
else:
189-
return func.HttpResponse(
190-
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
191-
status_code=200
201+
logging.info('Python HTTP trigger function processed a request.')
202+
return func.HttpResponse(
203+
"This HTTP triggered function executed successfully.",
204+
status_code=200
192205
)
193206
```
194207

@@ -197,10 +210,13 @@ def test_function(req: func.HttpRequest) -> func.HttpResponse:
197210
```python
198211
import logging
199212
import azure.functions as func
213+
200214
app = func.FunctionApp()
215+
201216
@app.function_name(name="QueueTrigger1")
202-
@app.queue_trigger(arg_name="msg", queue_name="python-queue-items",
203-
connection=""AzureWebJobsStorage"")
217+
@app.queue_trigger(arg_name="msg",
218+
queue_name="QUEUE_NAME",
219+
connection="CONNECTION_SETTING")
204220
def test_function(msg: func.QueueMessage):
205221
logging.info('Python EventHub trigger processed an event: %s',
206222
msg.get_body().decode('utf-8'))
@@ -211,10 +227,14 @@ def test_function(msg: func.QueueMessage):
211227
```python
212228
import logging
213229
import azure.functions as func
230+
214231
app = func.FunctionApp()
232+
215233
@app.function_name(name="QueueOutput1")
216234
@app.route(route="message")
217-
@app.queue_output(arg_name="msg", queue_name="python-queue-items", connection="AzureWebJobsStorage")
235+
@app.queue_output(arg_name="msg",
236+
queue_name="QUEUE_NAME",
237+
connection="CONNECTION_SETTING")
218238
def main(req: func.HttpRequest, msg: func.Out[str]) -> func.HttpResponse:
219239
input_msg = req.params.get('name')
220240
msg.set(input_msg)
@@ -228,9 +248,13 @@ def main(req: func.HttpRequest, msg: func.Out[str]) -> func.HttpResponse:
228248
```python
229249
import logging
230250
import azure.functions as func
251+
231252
app = func.FunctionApp()
253+
232254
@app.function_name(name="ServiceBusQueueTrigger1")
233-
@app.service_bus_queue_trigger(arg_name="msg", queue_name="myinputqueue", connection="CONNECTION_SETTING")
255+
@app.service_bus_queue_trigger(arg_name="msg",
256+
queue_name="QUEUE_NAME",
257+
connection="CONNECTION_SETTING")
234258
def test_function(msg: func.ServiceBusMessage):
235259
logging.info('Python ServiceBus queue trigger processed message: %s',
236260
msg.get_body().decode('utf-8'))
@@ -241,9 +265,14 @@ def test_function(msg: func.ServiceBusMessage):
241265
```python
242266
import logging
243267
import azure.functions as func
268+
244269
app = func.FunctionApp()
270+
245271
@app.function_name(name="ServiceBusTopicTrigger1")
246-
@app.service_bus_topic_trigger(arg_name="message", topic_name="mytopic", connection="CONNECTION_SETTING", subscription_name="testsub")
272+
@app.service_bus_topic_trigger(arg_name="message",
273+
topic_name="TOPIC_NAME",
274+
connection="CONNECTION_SETTING",
275+
subscription_name="SUBSCRIPTION_NAME")
247276
def test_function(message: func.ServiceBusMessage):
248277
message_body = message.get_body().decode("utf-8")
249278
logging.info("Python ServiceBus topic trigger processed message.")
@@ -255,12 +284,13 @@ def test_function(message: func.ServiceBusMessage):
255284
```python
256285
import logging
257286
import azure.functions as func
287+
258288
app = func.FunctionApp()
289+
259290
@app.route(route="put_message")
260-
@app.service_bus_topic_output(
261-
arg_name="message",
262-
connection="CONNECTION_SETTING",
263-
topic_name="mytopic")
291+
@app.service_bus_topic_output(arg_name="message",
292+
connection="CONNECTION_SETTING",
293+
topic_name="TOPIC_NAME")
264294
def main(req: func.HttpRequest, message: func.Out[str]) -> func.HttpResponse:
265295
input_msg = req.params.get('message')
266296
message.set(input_msg)
@@ -273,10 +303,13 @@ def main(req: func.HttpRequest, message: func.Out[str]) -> func.HttpResponse:
273303
import datetime
274304
import logging
275305
import azure.functions as func
306+
276307
app = func.FunctionApp()
308+
277309
@app.function_name(name="mytimer")
278-
@app.schedule(schedule="0 */5 * * * *", arg_name="mytimer", run_on_startup=True,
279-
use_monitor=False)
310+
@app.schedule(schedule="0 */5 * * * *",
311+
arg_name="mytimer",
312+
run_on_startup=True)
280313
def test_function(mytimer: func.TimerRequest) -> None:
281314
utc_timestamp = datetime.datetime.utcnow().replace(
282315
tzinfo=datetime.timezone.utc).isoformat()

0 commit comments

Comments
 (0)