Skip to content

Commit a0a1140

Browse files
authored
Merge pull request #293509 from lilyjma/patch-19
Update quickstart-python-vscode.md
2 parents dd8a862 + c4b4c5d commit a0a1140

File tree

1 file changed

+32
-198
lines changed

1 file changed

+32
-198
lines changed

articles/azure-functions/durable/quickstart-python-vscode.md

Lines changed: 32 additions & 198 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
---
22
title: "Quickstart: Create a Python Durable Functions app"
33
description: Create and publish a Python Durable Functions app in Azure Functions by using Visual Studio Code.
4-
author: davidmrdavid
4+
author: lilyjma
55
ms.topic: quickstart
6-
ms.date: 07/24/2024
7-
ms.reviewer: azfuncdf, davidmrdavid
6+
ms.date: 05/31/2025
7+
ms.reviewer: azfuncdf, lilyjma
88
ms.devlang: python
99
ms.custom: mode-api, devdivchpfy22, vscode-azure-extension-update-complete, devx-track-python
10-
zone_pivot_groups: python-mode-functions
1110
---
1211

1312
# Quickstart: Create a Python Durable Functions app
@@ -18,6 +17,9 @@ In this quickstart, you use the Durable Functions extension in Visual Studio Cod
1817

1918
:::image type="content" source="./media/quickstart-python-vscode/functions-vs-code-complete.png" alt-text="Screenshot of the running Durable Functions app in Azure.":::
2019

20+
> [!NOTE]
21+
> This quickstart uses the decorator-based [v2 programming model for Python](../functions-reference-python.md). This model gives a simpler file structure and is more code-centric compared to v1.
22+
2123
## Prerequisites
2224

2325
To complete this quickstart, you need:
@@ -30,7 +32,7 @@ To complete this quickstart, you need:
3032

3133
* An HTTP test tool that keeps your data secure. For more information, see [HTTP test tools](../functions-develop-local.md#http-test-tools).
3234

33-
* An Azure subscription. To use Durable Functions, you must have an Azure Storage account.
35+
* An Azure subscription for deploying app to Azure.
3436

3537
* [Python](https://www.python.org/) version 3.7, 3.8, 3.9, or 3.10 installed.
3638

@@ -46,8 +48,6 @@ In this section, you use Visual Studio Code to create a local Azure Functions pr
4648

4749
2. Select **Browse**. In the **Select Folder** dialog, go to a folder to use for your project, and then choose **Select**.
4850

49-
::: zone pivot="python-mode-configuration"
50-
5151
3. At the prompts, provide the following information:
5252

5353
| Prompt | Action | Description |
@@ -58,21 +58,6 @@ In this section, you use Visual Studio Code to create a local Azure Functions pr
5858
| **Select a template for your project's first function** | Select **Skip for now**. | |
5959
| **Select how you would like to open your project** | Select **Open in current window**. | Opens Visual Studio Code in the folder you selected. |
6060

61-
::: zone-end
62-
63-
::: zone pivot="python-mode-decorators"
64-
65-
3. At the prompts, provide the following information:
66-
67-
| Prompt | Value | Description |
68-
| ------ | ----- | ----------- |
69-
| **Select a language** | Select **Python (Programming Model V2)**. | Creates a local Python Functions project by using the V2 programming model. |
70-
| **Select a version** | Select **Azure Functions v4**. | You see this option only when Core Tools isn't already installed. In this case, Core Tools is installed the first time you run the app. |
71-
| **Python version** | Select **Python 3.7**, **Python 3.8**, **Python 3.9**, or **Python 3.10**. | Visual Studio Code creates a virtual environment by using the version you select. |
72-
| **Select how you would like to open your project** | Select **Open in current window**. | Opens Visual Studio Code in the folder you selected. |
73-
74-
::: zone-end
75-
7661
Visual Studio Code installs Azure Functions Core Tools if it's required to create a project. It also creates a function app project in a folder. This project contains the [host.json](../functions-host-json.md) and [local.settings.json](../functions-develop-local.md#local-settings-file) configuration files.
7762

7863
A *requirements.txt* file is also created in the root folder. It specifies the Python packages required to run your function app.
@@ -118,6 +103,9 @@ Then, in the integrated terminal where the virtual environment is activated, use
118103
python -m pip install -r requirements.txt
119104
```
120105

106+
> [!NOTE]
107+
> You must install [azure-functions-durable](https://pypi.org/project/azure-functions-durable/) v1.2.4 or above.
108+
121109
## Create your functions
122110

123111
The most basic Durable Functions app has three functions:
@@ -126,102 +114,7 @@ The most basic Durable Functions app has three functions:
126114
* **Activity function**: A function that is called by the orchestrator function, performs work, and optionally returns a value.
127115
* **Client function**: A regular function in Azure that starts an orchestrator function. This example uses an HTTP-triggered function.
128116

129-
::: zone pivot="python-mode-configuration"
130-
131-
### Orchestrator function
132-
133-
You use a template to create the Durable Functions app code in your project.
134-
135-
1. In the command palette, enter and then select **Azure Functions: Create Function**.
136-
137-
2. At the prompts, provide the following information:
138-
139-
| Prompt | Action | Description |
140-
| ------ | ----- | ----------- |
141-
| **Select a template for your function** | Select **Durable Functions orchestrator**. | Creates a Durable Functions app orchestration. |
142-
| **Provide a function name** | Select **HelloOrchestrator**. | A name for your durable function. |
143-
144-
You added an orchestrator to coordinate activity functions. Open *HelloOrchestrator/\_\_init__.py* to see the orchestrator function. Each call to `context.call_activity` invokes an activity function named `Hello`.
145-
146-
Next, you add the referenced `Hello` activity function.
147-
148-
### Activity function
149-
150-
1. In the command palette, enter and then select **Azure Functions: Create Function**.
151-
152-
2. At the prompts, provide the following information:
153-
154-
| Prompt | Action | Description |
155-
| ------ | ----- | ----------- |
156-
| **Select a template for your function** | Select **Durable Functions activity**. | Creates an activity function. |
157-
| **Provide a function name** | Enter **Hello**. | The name of your activity function. |
158-
159-
You added the `Hello` activity function that is invoked by the orchestrator. Open *Hello/\_\_init__.py* to see that it takes a name as input and returns a greeting. An activity function is where you perform actions such as making a database call or performing a computation.
160-
161-
Finally, you add an HTTP-triggered function that starts the orchestration.
162-
163-
### Client function (HTTP starter)
164-
165-
1. In the command palette, enter and then select **Azure Functions: Create Function**.
166-
167-
2. At the prompts, provide the following information:
168-
169-
| Prompt | Action | Description |
170-
| ------ | ----- | ----------- |
171-
| **Select a template for your function** | Select **Durable Functions HTTP starter**. | Creates an HTTP starter function. |
172-
| **Provide a function name** | Enter **DurableFunctionsHttpStart**. | The name of your client function |
173-
| **Authorization level** | Select **Anonymous**. | For demo purposes, this value allows the function to be called without using authentication. |
174-
175-
You added an HTTP-triggered function that starts an orchestration. Open *DurableFunctionsHttpStart/\_\_init__.py* to see that it uses `client.start_new` to start a new orchestration. Then it uses `client.create_check_status_response` to return an HTTP response containing URLs that can be used to monitor and manage the new orchestration.
176-
177-
You now have a Durable Functions app that can be run locally and deployed to Azure.
178-
179-
::: zone-end
180-
181-
::: zone pivot="python-mode-decorators"
182-
183-
## Requirements
184-
185-
Version 2 of the Python programming model requires the following minimum versions:
186-
187-
* [Azure Functions Runtime](../functions-versions.md) v4.16+
188-
* [Azure Functions Core Tools](../functions-run-local.md) v4.0.5095+ (if running locally)
189-
* [azure-functions-durable](https://pypi.org/project/azure-functions-durable/) v1.2.4+
190-
191-
## Enable the v2 programming model
192-
193-
The following application setting is required to run the v2 programming model:
194-
195-
* **Name**: `AzureWebJobsFeatureFlags`
196-
* **Value**: `EnableWorkerIndexing`
197-
198-
If you're running locally by using [Azure Functions Core Tools](../functions-run-local.md), add this setting to your *local.settings.json* file. If you're running in Azure, complete these steps by using a relevant tool:
199-
200-
# [Azure CLI](#tab/azure-cli-set-indexing-flag)
201-
202-
Replace `<FUNCTION_APP_NAME>` and `<RESOURCE_GROUP_NAME>` with the name of your function app and resource group, respectively.
203-
204-
```azurecli
205-
az functionapp config appsettings set --name <FUNCTION_APP_NAME> --resource-group <RESOURCE_GROUP_NAME> --settings AzureWebJobsFeatureFlags=EnableWorkerIndexing
206-
```
207-
208-
# [Azure PowerShell](#tab/azure-powershell-set-indexing-flag)
209-
210-
Replace `<FUNCTION_APP_NAME>` and `<RESOURCE_GROUP_NAME>` with the name of your function app and resource group, respectively.
211-
212-
```azurepowershell
213-
Update-AzFunctionAppSetting -Name <FUNCTION_APP_NAME> -ResourceGroupName <RESOURCE_GROUP_NAME> -AppSetting @{"AzureWebJobsFeatureFlags" = "EnableWorkerIndexing"}
214-
```
215-
216-
# [Visual Studio Code](#tab/vs-code-set-indexing-flag)
217-
218-
1. Make sure that you have the [Azure Functions extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions) installed.
219-
2. Select F1 to open the command palette. At the prompt (`>`), enter and then select **Azure Functions: Add New Setting**.
220-
3. Select your subscription and function app when you are prompted.
221-
4. For the name, enter **AzureWebJobsFeatureFlags**, and then select Enter.
222-
5. For the value, enter **EnableWorkerIndexing**, and then select Enter.
223-
224-
---
117+
## Sample code
225118

226119
To create a basic Durable Functions app by using these three function types, replace the contents of *function_app.py* with the following Python code:
227120

@@ -232,7 +125,7 @@ import azure.durable_functions as df
232125
myApp = df.DFApp(http_auth_level=func.AuthLevel.ANONYMOUS)
233126

234127
# An HTTP-triggered function with a Durable Functions client binding
235-
@myApp.route(route="orchestrators/{functionName}")
128+
@myApp.route(route="orchestrators/hello_orchestrator")
236129
@myApp.durable_client_input(client_name="client")
237130
async def http_start(req: func.HttpRequest, client):
238131
function_name = req.route_params.get('functionName')
@@ -264,90 +157,46 @@ Review the following table for an explanation of each function and its purpose i
264157
| `http_start` | An [HTTP-triggered function](../functions-bindings-http-webhook.md) that starts an instance of the orchestration and returns a `check status` response. |
265158

266159
> [!NOTE]
267-
> Durable Functions also supports Python v2 [blueprints](../functions-reference-python.md#blueprints). To use blueprints, register your blueprint functions by using the [azure-functions-durable](https://pypi.org/project/azure-functions-durable) `Blueprint` [class](https://github.com/Azure/azure-functions-durable-python/blob/dev/samples-v2/blueprint/durable_blueprints.py). You can register the resulting blueprint as usual. You can use our [sample](https://github.com/Azure/azure-functions-durable-python/tree/dev/samples-v2/blueprint) as an example.
268-
269-
::: zone-end
160+
> Durable Functions also supports Python v2 programming model [blueprints](../functions-reference-python.md#blueprints). To use blueprints, register your blueprint functions by using the [azure-functions-durable](https://pypi.org/project/azure-functions-durable) `Blueprint` [class](https://github.com/Azure/azure-functions-durable-python/blob/dev/samples-v2/blueprint/durable_blueprints.py). You can register the resulting blueprint as usual. You can use our [sample](https://github.com/Azure/azure-functions-durable-python/tree/dev/samples-v2/blueprint) as an example.
270161
271-
## Test the function locally
162+
## Configure storage emulator
272163

273-
Azure Functions Core Tools gives you the capability to run an Azure Functions project on your local development computer. If it isn't installed, you're prompted to install these tools the first time you start a function in Visual Studio Code.
164+
You can use [Azurite](../../storage/common/storage-use-azurite.md?tabs=visual-studio-code), an emulator for Azure Storage, to test the function locally. In *local.settings.json*, set the value for `AzureWebJobsStorage` to `UseDevelopmentStorage=true` like in this example:
274165

275-
::: zone pivot="python-mode-configuration"
166+
```json
167+
{
168+
"IsEncrypted": false,
169+
"Values": {
170+
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
171+
"FUNCTIONS_WORKER_RUNTIME": "python"
172+
}
173+
}
174+
```
276175

277-
1. To test your function, set a breakpoint in the `Hello` activity function code (in *Hello/\_\_init__.py*). Select F5 or select **Debug: Start Debugging** in the command palette to start the function app project. Output from Core Tools appears in the terminal panel.
176+
To install and start running the Azurite extension in Visual Studio Code, in the command palette, enter **Azurite: Start** and select Enter.
278177

279-
> [!NOTE]
280-
> For more information about debugging, see [Durable Functions diagnostics](durable-functions-diagnostics.md#debugging).
178+
You can use other storage options for your Durable Functions app. For more information about storage options and benefits, see [Durable Functions storage providers](durable-functions-storage-providers.md).
281179

282-
::: zone-end
180+
## Test the function locally
283181

284-
::: zone pivot="python-mode-decorators"
182+
Azure Functions Core Tools gives you the capability to run an Azure Functions project on your local development computer. If it isn't installed, you're prompted to install these tools the first time you start a function in Visual Studio Code.
285183

286184
1. To test your function, set a breakpoint in the `hello` activity function code. Select F5 or select **Debug: Start Debugging** in the command palette to start the function app project. Output from Core Tools appears in the terminal panel.
287185

288186
> [!NOTE]
289187
> For more information about debugging, see [Durable Functions diagnostics](durable-functions-diagnostics.md#debugging).
290188
291-
::: zone-end
292-
293-
2. Durable Functions requires an Azure storage account to run. When Visual Studio Code prompts you to select a storage account, select **Select storage account**.
294-
295-
:::image type="content" source="media/quickstart-python-vscode/functions-select-storage.png" alt-text="Screenshot of how to create a storage account.":::
296-
297-
3. At the prompts, provide the following information to create a new storage account in Azure.
298-
299-
| Prompt | Action | Description |
300-
| ------ | ----- | ----------- |
301-
| **Select subscription** | Select the name of your subscription. | Your Azure subscription. |
302-
| **Select a storage account** | Select **Create a new storage account**. | |
303-
| **Enter the name of the new storage account** | Enter a unique name. | The name of the storage account to create. |
304-
| **Select a resource group** | Enter a unique name. | The name of the resource group to create. |
305-
| **Select a location** | Select an Azure region. | Select a region that is close to you. |
306-
307-
4. In the terminal panel, copy the URL endpoint of your HTTP-triggered function.
189+
2. In the terminal panel, copy the URL endpoint of your HTTP-triggered function.
308190

309191
:::image type="content" source="media/quickstart-python-vscode/functions-f5.png" alt-text="Screenshot of Azure local output.":::
310192

311-
::: zone pivot="python-mode-configuration"
312-
313-
5. Use your browser or an HTTP test tool to send an HTTP POST request to the URL endpoint.
314-
315-
Replace the last segment with the name of the orchestrator function (`HelloOrchestrator`). The URL should be similar to `http://localhost:7071/api/orchestrators/HelloOrchestrator`.
316-
317-
The response is the HTTP function's initial result. It lets you know that the durable orchestration has started successfully. It doesn't yet display the end result of the orchestration. The response includes a few useful URLs. For now, query the status of the orchestration.
318-
319-
6. Copy the URL value for `statusQueryGetUri`, paste it in your browser's address bar, and execute the request. You can also continue to use your HTTP test tool to issue the GET request.
320-
321-
The request queries the orchestration instance for the status. You should see that the instance finished and that it includes the outputs or results of the durable function. It looks similar to this example:
322-
323-
```json
324-
{
325-
"name": "HelloOrchestrator",
326-
"instanceId": "9a528a9e926f4b46b7d3deaa134b7e8a",
327-
"runtimeStatus": "Completed",
328-
"input": null,
329-
"customStatus": null,
330-
"output": [
331-
"Hello Tokyo!",
332-
"Hello Seattle!",
333-
"Hello London!"
334-
],
335-
"createdTime": "2020-03-18T21:54:49Z",
336-
"lastUpdatedTime": "2020-03-18T21:54:54Z"
337-
}
338-
```
339-
340-
::: zone-end
341-
342-
::: zone pivot="python-mode-decorators"
343-
344-
5. Use your browser or an HTTP test tool to send an HTTP POST request to the URL endpoint.
193+
3. Use your browser or an HTTP test tool to send an HTTP POST request to the URL endpoint.
345194

346195
Replace the last segment with the name of the orchestrator function (`hello_orchestrator`). The URL should be similar to `http://localhost:7071/api/orchestrators/hello_orchestrator`.
347196

348197
The response is the HTTP function's initial result. It lets you know that the durable orchestration has started successfully. It doesn't yet display the end result of the orchestration. The response includes a few useful URLs. For now, query the status of the orchestration.
349198

350-
6. Copy the URL value for `statusQueryGetUri`, paste it in your browser's address bar, and execute the request. You can also continue to use your HTTP test tool to issue the GET request.
199+
4. Copy the URL value for `statusQueryGetUri`, paste it in your browser's address bar, and execute the request. You can also continue to use your HTTP test tool to issue the GET request.
351200

352201
The request queries the orchestration instance for the status. You should see that the instance finished and that it includes the outputs or results of the durable function. It looks similar to this example:
353202

@@ -368,10 +217,7 @@ Azure Functions Core Tools gives you the capability to run an Azure Functions pr
368217
}
369218
```
370219

371-
::: zone-end
372-
373-
374-
7. To stop debugging, in Visual Studio Code, select Shift+F5.
220+
5. To stop debugging, in Visual Studio Code, select Shift+F5.
375221

376222
After you verify that the function runs correctly on your local computer, it's time to publish the project to Azure.
377223

@@ -381,22 +227,10 @@ After you verify that the function runs correctly on your local computer, it's t
381227

382228
## Test your function in Azure
383229

384-
::: zone pivot="python-mode-configuration"
385-
386-
1. Copy the URL of the HTTP trigger from the output panel. The URL that calls your HTTP-triggered function must be in this format:
387-
388-
`https://<functionappname>.azurewebsites.net/api/orchestrators/HelloOrchestrator`
389-
390-
::: zone-end
391-
392-
::: zone pivot="python-mode-decorators"
393-
394230
1. Copy the URL of the HTTP trigger from the output panel. The URL that calls your HTTP-triggered function must be in this format:
395231

396232
`https://<functionappname>.azurewebsites.net/api/orchestrators/hello_orchestrator`
397233

398-
::: zone-end
399-
400234
2. Paste the new URL for the HTTP request in your browser's address bar. When you use the published app, you can expect to get the same status response that you got when you tested locally.
401235

402236
The Python Durable Functions app that you created and published by using Visual Studio Code is ready to use.

0 commit comments

Comments
 (0)