Skip to content

Commit 4695ee5

Browse files
authored
Merge pull request #23 from ggailey777/vameru/pystein-improvements
Updating PyStein Examples
2 parents 6875863 + 58d6b0d commit 4695ee5

14 files changed

+90
-56
lines changed

articles/azure-functions/functions-bindings-cosmosdb-v2-input.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,20 +1531,24 @@ The following example shows an Azure Cosmos DB input binding. The function reads
15311531
# [v2](#tab/python-v2)
15321532

15331533
```python
1534+
import logging
1535+
import azure.functions as func
1536+
1537+
app = func.FunctionApp()
1538+
15341539
@app.queue_trigger(arg_name="msg",
1535-
queue_name="outqueue",
1536-
connection="AzureWebJobsStorage")
1537-
@app.cosmos_db_input(
1538-
arg_name="documents",
1539-
database_name="MyDatabase",
1540-
collection_name="MyCollection",
1541-
id="{msg.payload_property}",
1542-
partition_key="{msg.payload_property}",
1543-
connection_string_setting="MyAccount_COSMOSDB")
1540+
queue_name="outqueue",
1541+
connection="AzureWebJobsStorage")
1542+
@app.cosmos_db_input(arg_name="documents",
1543+
database_name="MyDatabase",
1544+
collection_name="MyCollection",
1545+
id="{msg.payload_property}",
1546+
partition_key="{msg.payload_property}",
1547+
connection_string_setting="MyAccount_COSMOSDB")
15441548
@app.cosmos_db_output(arg_name="outputDocument",
1545-
database_name="MyDatabase",",
1546-
collection_name="MyCollection",
1547-
connection_string_setting="MyAccount_COSMOSDB")
1549+
database_name="MyDatabase",
1550+
collection_name="MyCollection",
1551+
connection_string_setting="MyAccount_COSMOSDB")
15481552
def test_function(msg: func.QueueMessage,
15491553
inputDocument: func.DocumentList,
15501554
outputDocument: func.Out[func.Document]):

articles/azure-functions/functions-bindings-cosmosdb-v2-output.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,15 @@ The following example demonstrates how to write a document to an Azure Cosmos DB
596596
```python
597597
import logging
598598
import azure.functions as func
599+
600+
app = func.FunctionApp()
601+
599602
@app.route()
600-
@app.cosmos_db_output(
601-
arg_name="documents", database_name="<DB_NAME>",
602-
collection_name="<COLLECTION_NAME>",
603-
create_if_not_exists=True,
604-
connection_string_setting="CONNECTION_SETTING")
603+
@app.cosmos_db_output(arg_name="documents",
604+
database_name="DB_NAME",
605+
collection_name="COLLECTION_NAME",
606+
create_if_not_exists=True,
607+
connection_string_setting="CONNECTION_SETTING")
605608
def main(req: func.HttpRequest, documents: func.Out[func.Document]) -> func.HttpResponse:
606609
request_body = req.get_body()
607610
documents.set(func.Document.from_json(request_body))

articles/azure-functions/functions-bindings-cosmosdb-v2-trigger.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,14 @@ The following example shows an Azure Cosmos DB trigger binding. The example depe
294294
```python
295295
import logging
296296
import azure.functions as func
297+
297298
app = func.FunctionApp()
298-
@app.function_name(name="CosmosDBTrigger1")
299-
@app.cosmos_db_trigger(arg_name="documents", database_name="<DB_NAME>", collection_name="<COLLECTION_NAME>", connection_string_setting=""AzureWebJobsStorage"",
299+
300+
@app.function_name(name="CosmosDBTrigger")
301+
@app.cosmos_db_trigger(arg_name="documents",
302+
database_name="DB_NAME",
303+
collection_name="COLLECTION_NAME",
304+
connection_string_setting="CONNECTION_SETTING",
300305
lease_collection_name="leases", create_lease_collection_if_not_exists="true")
301306
def test_function(documents: func.DocumentList) -> str:
302307
if documents:

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,14 @@ The following example shows an event hub trigger binding and a Python function t
195195
```python
196196
import logging
197197
import azure.functions as func
198+
198199
app = func.FunctionApp()
200+
199201
@app.function_name(name="eventhub_output")
200202
@app.route(route="eventhub_output")
201203
@app.event_hub_output(arg_name="event",
202-
event_hub_name="samples-workitems",
203-
connection="CONNECTION_SETTING")
204+
event_hub_name="<EVENT_HUB_NAME>",
205+
connection="<CONNECTION_SETTING>")
204206
def eventhub_output(req: func.HttpRequest, event: func.Out[str]):
205207
body = req.get_body()
206208
if body is not None:

articles/azure-functions/functions-bindings-http-webhook-trigger.md

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -467,25 +467,16 @@ The following example shows a trigger binding and a Python function that uses th
467467
```python
468468
import azure.functions as func
469469
import logging
470-
app = func.FunctionApp(auth_level=func.AuthLevel.ANONYMOUS)
470+
471+
app = func.FunctionApp()
472+
471473
@app.function_name(name="HttpTrigger1")
472-
@app.route(route="hello")
474+
@app.route(route="hello", auth_level=func.AuthLevel.ANONYMOUS)
473475
def test_function(req: func.HttpRequest) -> func.HttpResponse:
474-
logging.info('Python HTTP trigger function processed a request.')
475-
name = req.params.get('name')
476-
if not name:
477-
try:
478-
req_body = req.get_json()
479-
except ValueError:
480-
pass
481-
else:
482-
name = req_body.get('name')
483-
if name:
484-
return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
485-
else:
486-
return func.HttpResponse(
487-
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
488-
status_code=200
476+
logging.info('Python HTTP trigger function processed a request.')
477+
return func.HttpResponse(
478+
"This HTTP triggered function executed successfully.",
479+
status_code=200
489480
)
490481
```
491482

articles/azure-functions/functions-bindings-service-bus-output.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,13 @@ The following example demonstrates how to write out to a Service Bus queue in Py
240240
```python
241241
import logging
242242
import azure.functions as func
243+
243244
app = func.FunctionApp()
245+
244246
@app.route(route="put_message")
245-
@app.service_bus_topic_output(
246-
arg_name="message",
247-
connection="CONNECTION_SETTING",
248-
topic_name="mytopic")
247+
@app.service_bus_topic_output(arg_name="message",
248+
connection="<CONNECTION_SETTING>",
249+
topic_name="<TOPIC_NAME>")
249250
def main(req: func.HttpRequest, message: func.Out[str]) -> func.HttpResponse:
250251
input_msg = req.params.get('message')
251252
message.set(input_msg)

articles/azure-functions/functions-bindings-service-bus-trigger.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,13 @@ The following example demonstrates how to read a Service Bus queue message via a
213213
```python
214214
import logging
215215
import azure.functions as func
216+
216217
app = func.FunctionApp()
218+
217219
@app.function_name(name="ServiceBusQueueTrigger1")
218-
@app.service_bus_queue_trigger(arg_name="msg", queue_name="myinputqueue", connection="CONNECTION_SETTING")
220+
@app.service_bus_queue_trigger(arg_name="msg",
221+
queue_name="<QUEUE_NAME>",
222+
connection="<CONNECTION_SETTING">)
219223
def test_function(msg: func.ServiceBusMessage):
220224
logging.info('Python ServiceBus queue trigger processed message: %s',
221225
msg.get_body().decode('utf-8'))

articles/azure-functions/functions-bindings-storage-blob-input.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,17 @@ The code creates a copy of a blob.
253253
```python
254254
import logging
255255
import azure.functions as func
256+
256257
app = func.FunctionApp()
258+
257259
@app.function_name(name="BlobOutput1")
258260
@app.route(route="file")
259261
@app.blob_input(arg_name="inputblob",
260262
path="sample-workitems/test.txt",
261-
connection="AzureWebJobsStorage")
263+
connection="<BLOB_CONNECTION_SETTING>")
262264
@app.blob_output(arg_name="outputblob",
263265
path="newblob/test.txt",
264-
connection="AzureWebJobsStorage")
266+
connection="<BLOB_CONNECTION_SETTING>")
265267
def main(req: func.HttpRequest, inputblob: str, outputblob: func.Out[str]):
266268
logging.info(f'Python Queue trigger function processed {len(inputblob)} bytes')
267269
outputblob.set(inputblob)

articles/azure-functions/functions-bindings-storage-blob-output.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,17 @@ The code creates a copy of a blob.
318318
```python
319319
import logging
320320
import azure.functions as func
321+
321322
app = func.FunctionApp()
323+
322324
@app.function_name(name="BlobOutput1")
323325
@app.route(route="file")
324326
@app.blob_input(arg_name="inputblob",
325327
path="sample-workitems/test.txt",
326-
connection="AzureWebJobsStorage")
328+
connection="<BLOB_CONNECTION_SETTING>")
327329
@app.blob_output(arg_name="outputblob",
328330
path="newblob/test.txt",
329-
connection="AzureWebJobsStorage")
331+
connection="<BLOB_CONNECTION_SETTING>")
330332
def main(req: func.HttpRequest, inputblob: str, outputblob: func.Out[str]):
331333
logging.info(f'Python Queue trigger function processed {len(inputblob)} bytes')
332334
outputblob.set(inputblob)

articles/azure-functions/functions-bindings-storage-blob-trigger.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,13 @@ The following example shows a blob trigger binding. The example depends on wheth
217217
```python
218218
import logging
219219
import azure.functions as func
220+
220221
app = func.FunctionApp()
222+
221223
@app.function_name(name="BlobTrigger1")
222-
@app.blob_trigger(arg_name="myblob", path="samples-workitems/{name}",
223-
connection="AzureWebJobsStorage")
224+
@app.blob_trigger(arg_name="myblob",
225+
path="PATH/TO/BLOB",
226+
connection="CONNECTION_SETTING")
224227
def test_function(myblob: func.InputStream):
225228
logging.info(f"Python blob trigger function processed blob \n"
226229
f"Name: {myblob.name}\n"

0 commit comments

Comments
 (0)