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
Verify your prerequisites, which depend on whether you're using Azure CLI or Azure PowerShell for creating Azure resources.
49
-
50
-
# [Azure CLI](#tab/azure-cli)
51
-
52
-
::: zone pivot="python-mode-configuration"
53
-
+ In a terminal or command window, run `func --version` to check that the Azure Functions Core Tools version is 4.x.
54
-
::: zone-end
55
-
::: zone pivot="python-mode-decorators"
56
-
+ In a terminal or command window, run `func --version` to check that the Azure Functions Core Tools version is 4.0.4785 or later.
57
-
::: zone-end
58
-
+ Run `az --version` to check that the Azure CLI version is 2.4 or later.
59
-
60
-
+ Run `az login` to sign in to Azure and verify an active subscription.
61
-
62
-
+ Run `python --version` (Linux/macOS) or `py --version` (Windows) to check your Python version reports 3.9.x, 3.8.x, or 3.7.x.
63
-
64
-
# [Azure PowerShell](#tab/azure-powershell)
65
-
66
-
+ In a terminal or command window, run `func --version` to check that the Azure Functions Core Tools version is 4.x.
67
-
68
-
+ Run `(Get-Module -ListAvailable Az).Version` and verify version 5.0 or later.
69
-
70
-
+ Run `Connect-AzAccount` to sign in to Azure and verify an active subscription.
71
-
72
-
+ Run `python --version` (Linux/macOS) or `py --version` (Windows) to check your Python version reports 3.9.x, 3.8.x, or 3.7.x.
73
-
74
-
---
75
-
76
46
## <aname="create-venv"></a>Create and activate a virtual environment
77
47
78
48
In a suitable folder, run the following commands to create and activate a virtual environment named `.venv`. Make sure that you're using Python 3.9, 3.8, or 3.7, which are supported by Azure Functions.
@@ -143,14 +113,9 @@ In Azure Functions, a function project is a container for one or more individual
143
113
```
144
114
145
115
`func new` creates a subfolder matching the function name that contains a code file appropriate to the project's chosen language and a configuration file named *function.json*.
146
-
147
-
Get the list of templates by using the following command:
148
-
149
-
```console
150
-
func templates list -l python
151
-
```
152
-
::: zone-end
153
-
::: zone pivot="python-mode-decorators"
116
+
```
117
+
::: zone-end
118
+
::: zone pivot="python-mode-decorators"
154
119
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.
155
120
156
121
```console
@@ -162,21 +127,22 @@ In Azure Functions, a function project is a container for one or more individual
162
127
```console
163
128
cd LocalFunctionProj
164
129
```
165
-
130
+
166
131
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.
167
132
168
133
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.
return func.HttpResponse("HttpTrigger1 function processed a request!")
144
+
```
145
+
180
146
1. Open the local.settings.json project file and verify that the `AzureWebJobsFeatureFlags` setting has a value of `EnableWorkerIndexing`. This is required for Functions to interpret your project correctly as the Python v2 model. You'll add this same setting to your application settings after you publish your project to Azure.
181
147
182
148
1. In the local.settings.json file, update the `AzureWebJobsStorage` setting as in the following example:
@@ -185,37 +151,9 @@ In Azure Functions, a function project is a container for one or more individual
This tells the local Functions host to use the storage emulator for the storage connection currently required by the Python v2 model. When you publish your project to Azure, you'll need to instead use the default storage account. If you're instead using an Azure Storage account, set your storage account connection string here.
189
-
::: zone-end
190
-
191
-
### (Optional) Examine the file contents
192
-
193
-
If desired, you can skip to [Run the function locally](#run-the-function-locally) and examine the file contents later.
194
-
195
-
::: zone pivot="python-mode-configuration"
196
-
#### \_\_init\_\_.py
197
-
198
-
*\_\_init\_\_.py* contains a `main()` Python function that's triggered according to the configuration in *function.json*.
For an HTTP trigger, the function receives request data in the variable `req` as defined in *function.json*. `req` is an instance of the [azure.functions.HttpRequest class](/python/api/azure-functions/azure.functions.httprequest). The return object, defined as `$return` in *function.json*, is an instance of [azure.functions.HttpResponse class](/python/api/azure-functions/azure.functions.httpresponse). For more information, see [Azure Functions HTTP triggers and bindings](./functions-bindings-http-webhook.md?tabs=python).
203
-
204
-
#### function.json
205
-
206
-
*function.json* is a configuration file that defines the input and output `bindings` for the function, including the trigger type.
207
-
208
-
If desired, you can change `scriptFile` to invoke a different Python 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).
213
-
::: zone-end
214
-
::: zone pivot="python-mode-decorators"
215
-
`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.
216
-
217
-
For more information, see [Azure Functions HTTP triggers and bindings](./functions-bindings-http-webhook.md?tabs=python).
218
-
154
+
This tells the local Functions host to use the storage emulator for the storage connection currently required by the Python v2 model. When you publish your project to Azure, you'll need to instead use the default storage account. If you're instead using an Azure Storage account, set your storage account connection string here.
155
+
::: zone-end
156
+
::: zone pivot="python-mode-decorators"
219
157
## Start the storage emulator
220
158
221
159
By default, local development uses the Azurite storage emulator. This emulator is used when the `AzureWebJobsStorage` setting in the *local.settings.json* project file is set to `UseDevelopmentStorage=true`. When using the emulator, you must start the local Azurite storage emulator before running the function.
0 commit comments