You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this article, you use command-line tools to create a Python function that responds to HTTP requests. After testing the code locally, you deploy it to the serverless environment of Azure Functions.
15
+
16
+
This article covers both Python programming models supported by Azure Functions. Use the selector at the top to choose your programming model.
17
17
18
-
In this article, you use command-line tools to create a Python function that responds to HTTP requests. After testing the code locally, you deploy it to the serverless environment of Azure Functions.
18
+
>[!NOTE]
19
+
>The Python v2 programming model for Functions is currently in Preview. To learn more about the Python v2 programming model, see the [Developer Reference Guide](functions-reference-python.md).
19
20
20
21
Completing this quickstart incurs a small cost of a few USD cents or less in your Azure account.
21
22
@@ -27,24 +28,35 @@ Before you begin, you must have the following requirements in place:
27
28
28
29
+ An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio).
29
30
31
+
::: zone pivot="python-mode-configuration"
30
32
+ The [Azure Functions Core Tools](functions-run-local.md#v2) version 4.x.
31
-
33
+
::: zone-end
34
+
::: zone pivot="python-mode-decorators"
35
+
+ The [Azure Functions Core Tools](functions-run-local.md#v2) version 4.0.4785 or later.
36
+
::: zone-end
32
37
+ One of the following tools for creating Azure resources:
33
38
34
39
+[Azure CLI](/cli/azure/install-azure-cli) version 2.4 or later.
35
40
36
41
+ The Azure [Az PowerShell module](/powershell/azure/install-az-ps) version 5.9.0 or later.
37
42
38
43
+[Python versions that are supported by Azure Functions](supported-languages.md#languages-by-runtime-version).
44
+
::: zone pivot="python-mode-decorators"
45
+
+ The [Azurite storage emulator](../storage/common/storage-use-azurite.md?tabs=npm#install-azurite). While you can also use an actual Azure Storage account, the article assumes you're using this emulator.
46
+
::: zone-end
39
47
40
48
### Prerequisite check
41
49
42
50
Verify your prerequisites, which depend on whether you're using Azure CLI or Azure PowerShell for creating Azure resources.
43
51
44
52
# [Azure CLI](#tab/azure-cli)
45
53
54
+
::: zone pivot="python-mode-configuration"
46
55
+ In a terminal or command window, run `func --version` to check that the Azure Functions Core Tools version is 4.x.
47
-
56
+
::: zone-end
57
+
::: zone pivot="python-mode-decorators"
58
+
+ In a terminal or command window, run `func --version` to check that the Azure Functions Core Tools version is 4.0.4785 or later.
59
+
::: zone-end
48
60
+ Run `az --version` to check that the Azure CLI version is 2.4 or later.
49
61
50
62
+ Run `az login` to sign in to Azure and verify an active subscription.
@@ -111,6 +123,7 @@ You run all subsequent commands in this activated virtual environment.
111
123
112
124
In Azure Functions, a function project is a container for one or more individual functions that each responds to a specific trigger. All functions in a project share the same local and hosting configurations. In this section, you create a function project that contains a single function.
113
125
126
+
::: zone pivot="python-mode-configuration"
114
127
1. Run the `func init` command as follows to create a functions project in a folder named *LocalFunctionProj* with the specified runtime.
115
128
116
129
```console
@@ -138,11 +151,41 @@ In Azure Functions, a function project is a container for one or more individual
138
151
```console
139
152
func templates list -l python
140
153
```
154
+
::: zone-end
155
+
::: zone pivot="python-mode-decorators"
156
+
1. Run the `func init` command as follows to create a functions project in a folder named *LocalFunctionProj* with the specified runtime and the specified programming model version.
157
+
158
+
```console
159
+
func init LocalFunctionProj --python -m V2
160
+
```
161
+
162
+
1. Go to the project folder.
163
+
164
+
```console
165
+
cd LocalFunctionProj
166
+
```
167
+
168
+
This folder contains various files for the project, including configuration files named *[local.settings.json]*(functions-develop-local.md#local-settings-file) and *[host.json]*(functions-host-json.md). Because *local.settings.json* can contain secrets downloaded from Azure, the file is excluded from source control by default in the *.gitignore* file.
169
+
170
+
1. The file `function_app.py` can include all functions within your project. To start with, there's already an HTTP function stored in the file.
Each binding requires a direction, a type, and a unique name. The HTTP trigger has an input binding of type [`httpTrigger`](functions-bindings-http-webhook-trigger.md) and output binding of type [`http`](functions-bindings-http-webhook-output.md).
206
+
::: zone-end
207
+
::: zone pivot="python-mode-decorators"
208
+
`function_app.py` is the entry point to the function and where functions will be stored and/or referenced. This file will include configuration of triggers and bindings through decorators, and the function content itself.
209
+
210
+
For more information, see [Azure Functions HTTP triggers and bindings](./functions-bindings-http-webhook.md?tabs=python).
211
+
212
+
## Start the storage emulator
213
+
214
+
Before running the function locally, you must start the local Azurite storage emulator. You can skip this step if the `AzureWebJobsStorage` setting in the local.settings.json file is set to the connection string for an Azure Storage account.
215
+
216
+
Use the following command to start the Azurite storage emulator:
217
+
218
+
```cmd
219
+
azurite
220
+
```
221
+
222
+
For more information, see [Run Azurite](../storage/common/storage-use-azurite.md?tabs=npm#run-azurite)
@@ -180,7 +241,7 @@ Use the following commands to create these items. Both Azure CLI and PowerShell
180
241
az login
181
242
```
182
243
183
-
The [az login](/cli/azure/reference-index#az-login) command signs you into your Azure account.
244
+
The [`az login`](/cli/azure/reference-index#az-login) command signs you into your Azure account.
184
245
185
246
# [Azure PowerShell](#tab/azure-powershell)
186
247
```azurepowershell
@@ -224,6 +285,10 @@ Use the following commands to create these items. Both Azure CLI and PowerShell
224
285
225
286
---
226
287
288
+
::: zone pivot="python-mode-decorators"
289
+
In the current v2 programming model preview, choose a region from one of the following locations: France Central, West Central US, North Europe, China East, East US, or North Central US.
290
+
::: zone-end
291
+
227
292
> [!NOTE]
228
293
> You can't host Linux and Windows apps in the same resource group. If you have an existing resource group named `AzureFunctionsQuickstart-rg` with a Windows function app or web app, you must use a different resource group.
229
294
@@ -273,11 +338,35 @@ Use the following commands to create these items. Both Azure CLI and PowerShell
273
338
274
339
In the previous example, replace `<APP_NAME>` with a globally unique name appropriate to you. The `<APP_NAME>` is also the default DNS domain for the function app.
275
340
276
-
This command creates a function app running in your specified language runtime under the [Azure Functions Consumption Plan](consumption-plan.md), which is free for the amount of usage you incur here. The command also provisions an associated Azure Application Insights instance in the same resource group, with which you can monitor your function app and view logs. For more information, see [Monitor Azure Functions](functions-monitoring.md). The instance incurs no costs until you activate it.
341
+
This command creates a function app running in your specified language runtime under the [Azure Functions Consumption Plan](consumption-plan.md), which is free for the amount of usage you incur here. The command also creates an associated Azure Application Insights instance in the same resource group, with which you can monitor your function app and view logs. For more information, see [Monitor Azure Functions](functions-monitoring.md). The instance incurs no costs until you activate it.
To use the Python v2 model in your function app, you need to add a new application setting in Azure named `AzureWebJobsFeatureFlags` with a value of `EnableWorkerIndexing`. This setting is already in your local.settings.json file.
349
+
350
+
Run the following command to add this setting to your new function app in Azure.
351
+
352
+
# [Azure CLI](#tab/azure-cli)
353
+
354
+
```azurecli
355
+
az functionapp config appsettings set --name <FUNCTION_APP_NAME> --resource-group <RESOURCE_GROUP_NAME> --settings AzureWebJobsFeatureFlags=EnableWorkerIndexing
In the previous example, replace `<FUNCTION_APP_NAME>` and `<RESOURCE_GROUP_NAME>` with the name of your function app and resource group, respectively. This setting is already in your local.settings.json file.
367
+
::: zone-end
368
+
369
+
## Verify in Azure
281
370
282
371
Run the following command to view near real-time [streaming logs](functions-run-local.md#enable-streaming-logs) in Application Insights in the Azure portal.
283
372
@@ -294,4 +383,7 @@ In a separate terminal window or in the browser, call the remote function again.
294
383
> [!div class="nextstepaction"]
295
384
> [Connect to an Azure Storage queue](functions-add-output-binding-storage-queue-cli.md?pivots=programming-language-python)
296
385
297
-
[Having issues? Let us know.](https://aka.ms/python-functions-qs-survey)
386
+
Having issues with this article?
387
+
388
+
+[Troubleshoot Python function apps in Azure Functions](recover-python-functions.md)
389
+
+[Let us know](https://aka.ms/python-functions-qs-survey)
0 commit comments