Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
GitHub Copilot for Azure plugin providing Azure service management and development assistance inside Claude Code and IDEs.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/services/functions/runtimes/python.md
1# Python — Azure Functions v2 Triggers & Bindings23> **Model**: Python v2 programming model. **NO** `function.json` files.4> Entry point: `function_app.py`5> Import: `import azure.functions as func`67## Lambda Migration Rules89> Shared rules (bindings over SDKs, latest runtime, identity-first auth) → [global-rules.md](../global-rules.md)1011Python-specific: all functions use the v2 decorator model shown throughout this file. No additional migration rules beyond global.1213## HTTP Trigger1415```python16@app.route(route="hello", methods=["GET", "POST"], auth_level=func.AuthLevel.ANONYMOUS)17def http_function(req: func.HttpRequest) -> func.HttpResponse:18name = req.params.get('name') or req.get_body().decode()19return func.HttpResponse(f"Hello, {name}!")20```2122## Blob Storage2324```python25# Trigger (use EventGrid source)26@app.blob_trigger(arg_name="myblob", path="samples-workitems/{name}",27connection="AzureWebJobsStorage", source="EventGrid")28def blob_trigger(myblob: func.InputStream):29logging.info(f"Blob: {myblob.name}, Size: {myblob.length}")3031# Input32@app.blob_input(arg_name="inputblob", path="input/{name}", connection="AzureWebJobsStorage")3334# Output35@app.blob_output(arg_name="outputblob", path="output/{name}", connection="AzureWebJobsStorage")36```3738## Queue Storage3940```python41# Trigger42@app.queue_trigger(arg_name="msg", queue_name="myqueue-items",43connection="AzureWebJobsStorage")44def queue_trigger(msg: func.QueueMessage):45logging.info(f"Queue message: {msg.get_body().decode()}")4647# Output48@app.queue_output(arg_name="outputmsg", queue_name="outqueue",49connection="AzureWebJobsStorage")50```5152## Timer5354```python55@app.timer_trigger(schedule="0 */5 * * * *", arg_name="mytimer",56run_on_startup=False)57def timer_function(mytimer: func.TimerRequest):58logging.info("Timer triggered")59```6061## Event Grid6263```python64# Trigger65@app.event_grid_trigger(arg_name="event")66def eventgrid_trigger(event: func.EventGridEvent):67logging.info(f"Event: {event.subject} - {event.event_type}")6869# Output70@app.event_grid_output(arg_name="outputEvent",71topic_endpoint_uri="MyEventGridTopicUriSetting",72topic_key_setting="MyEventGridTopicKeySetting")73```7475## Cosmos DB7677```python78# Trigger (Change Feed)79@app.cosmos_db_trigger_v3(arg_name="documents",80connection="CosmosDBConnection",81database_name="mydb",82container_name="mycontainer",83create_lease_container_if_not_exists=True)84def cosmosdb_trigger(documents: func.DocumentList):85for doc in documents:86logging.info(f"Changed doc: {doc['id']}")8788# Input89@app.cosmos_db_input(arg_name="doc", connection="CosmosDBConnection",90database_name="mydb", container_name="mycontainer",91id="{id}", partition_key="{partitionKey}")9293# Output94@app.cosmos_db_output(arg_name="newdoc", connection="CosmosDBConnection",95database_name="mydb", container_name="mycontainer")96```9798## Service Bus99100```python101# Queue Trigger102@app.service_bus_queue_trigger(arg_name="msg", queue_name="myqueue",103connection="ServiceBusConnection")104def sb_queue_trigger(msg: func.ServiceBusMessage):105logging.info(f"Message: {msg.get_body().decode()}")106107# Topic Trigger108@app.service_bus_topic_trigger(arg_name="msg", topic_name="mytopic",109subscription_name="mysubscription",110connection="ServiceBusConnection")111def sb_topic_trigger(msg: func.ServiceBusMessage):112logging.info(f"Topic message: {msg.get_body().decode()}")113114# Output115@app.service_bus_queue_output(arg_name="outmsg", queue_name="outqueue",116connection="ServiceBusConnection")117```118119## Event Hubs120121```python122# Trigger123@app.event_hub_message_trigger(arg_name="event", event_hub_name="myeventhub",124connection="EventHubConnection",125cardinality="many")126def eventhub_trigger(event: func.EventHubEvent):127logging.info(f"Event: {event.get_body().decode()}")128129# Output130@app.event_hub_output(arg_name="outevent", event_hub_name="outeventhub",131connection="EventHubConnection")132```133134## Table Storage135136```python137# Input138@app.table_input(arg_name="tableEntity", table_name="mytable",139partition_key="{partitionKey}", row_key="{rowKey}",140connection="AzureWebJobsStorage")141142# Output143@app.table_output(arg_name="tableOut", table_name="mytable",144connection="AzureWebJobsStorage")145```146147## SQL148149```python150# Trigger151@app.sql_trigger(arg_name="changes", table_name="dbo.MyTable",152connection_string_setting="SqlConnection")153def sql_trigger(changes: func.SqlRowList):154for change in changes:155logging.info(f"Change: {change}")156157# Input158@app.sql_input(arg_name="items",159command_text="SELECT * FROM dbo.MyTable WHERE Id = @Id",160command_type="Text", parameters="@Id={id}",161connection_string_setting="SqlConnection")162163# Output164@app.sql_output(arg_name="newitem", command_text="dbo.MyTable",165connection_string_setting="SqlConnection")166```167168## SignalR169170```python171@app.generic_output_binding(arg_name="signalr", type="signalR",172hub_name="myhub",173connection_string_setting="AzureSignalRConnectionString")174```175176## SendGrid177178```python179@app.generic_output_binding(arg_name="mail", type="sendGrid",180api_key="SendGridApiKey",181from_address="[email protected]")182```183184## Combining Decorators185186```python187@app.route(route="process", methods=["POST"])188@app.cosmos_db_input(arg_name="doc", connection="CosmosDBConnection",189database_name="mydb", container_name="mycontainer",190id="{id}", partition_key="{pk}")191@app.queue_output(arg_name="outmsg", queue_name="outqueue",192connection="AzureWebJobsStorage")193def process_item(req: func.HttpRequest, doc: func.DocumentList,194outmsg: func.Out[str]) -> func.HttpResponse:195outmsg.set(doc[0].to_json())196return func.HttpResponse("Processed")197```198199> Full reference: [Azure Functions Python developer guide](https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python)200