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
@@ -28,12 +28,8 @@ Before you begin, you must have the following requirements in place:
28
28
29
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).
30
30
31
-
::: zone pivot="python-mode-configuration"
32
31
+ The [Azure Functions Core Tools](functions-run-local.md#v2) version 4.x.
33
-
::: zone-end
34
-
::: zone pivot="python-mode-decorators"
35
-
+ The [Azure Functions Core Tools](functions-run-local.md#v2) version 4.2.1 or later.
36
-
::: zone-end
32
+
37
33
+ One of the following tools for creating Azure resources:
38
34
39
35
+[Azure CLI](/cli/azure/install-azure-cli) version 2.4 or later.
@@ -47,36 +43,6 @@ Before you begin, you must have the following requirements in place:
Verify your prerequisites, which depend on whether you're using Azure CLI or Azure PowerShell for creating Azure resources.
53
-
54
-
# [Azure CLI](#tab/azure-cli)
55
-
56
-
::: zone pivot="python-mode-configuration"
57
-
+ In a terminal or command window, run `func --version` to check that the Azure Functions Core Tools version is 4.x.
58
-
::: zone-end
59
-
::: zone pivot="python-mode-decorators"
60
-
+ In a terminal or command window, run `func --version` to check that the Azure Functions Core Tools version is 4.0.4785 or later.
61
-
::: zone-end
62
-
+ Run `az --version` to check that the Azure CLI version is 2.4 or later.
63
-
64
-
+ Run `az login` to sign in to Azure and verify an active subscription.
65
-
66
-
+ 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.
67
-
68
-
# [Azure PowerShell](#tab/azure-powershell)
69
-
70
-
+ In a terminal or command window, run `func --version` to check that the Azure Functions Core Tools version is 4.x.
71
-
72
-
+ Run `(Get-Module -ListAvailable Az).Version` and verify version 5.0 or later.
73
-
74
-
+ Run `Connect-AzAccount` to sign in to Azure and verify an active subscription.
75
-
76
-
+ 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.
77
-
78
-
---
79
-
80
46
## <aname="create-venv"></a>Create and activate a virtual environment
81
47
82
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.
@@ -146,15 +112,9 @@ In Azure Functions, a function project is a container for one or more individual
146
112
func new --name HttpExample --template "HTTP trigger" --authlevel "anonymous"
147
113
```
148
114
149
-
`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*.
150
-
151
-
Get the list of templates by using the following command:
152
-
153
-
```console
154
-
func templates list -l python
155
-
```
156
-
::: zone-end
157
-
::: zone pivot="python-mode-decorators"
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*.
116
+
::: zone-end
117
+
::: zone pivot="python-mode-decorators"
158
118
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.
159
119
160
120
```console
@@ -166,51 +126,33 @@ In Azure Functions, a function project is a container for one or more individual
166
126
```console
167
127
cd LocalFunctionProj
168
128
```
169
-
129
+
170
130
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.
171
131
172
132
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.
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).
198
-
199
-
#### function.json
200
-
201
-
*function.json* is a configuration file that defines the input and output `bindings` for the function, including the trigger type.
202
-
203
-
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).
208
-
::: zone-end
209
-
::: zone pivot="python-mode-decorators"
210
-
`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.
211
-
212
-
For more information, see [Azure Functions HTTP triggers and bindings](./functions-bindings-http-webhook.md?tabs=python).
return func.HttpResponse("HttpTrigger1 function processed a request!")
143
+
```
144
+
145
+
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.
146
+
147
+
1. In the local.settings.json file, update the `AzureWebJobsStorage` setting as in the following example:
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.
154
+
::: zone-end
155
+
::: zone pivot="python-mode-decorators"
214
156
## Start the storage emulator
215
157
216
158
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.
Copy file name to clipboardExpand all lines: articles/azure-functions/create-first-function-vs-code-python.md
+8-44Lines changed: 8 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,7 +75,6 @@ In this section, you use Visual Studio Code to create a local Azure Functions pr
75
75
|**Select a template for your project's first function**| Choose `HTTP trigger`.|
76
76
|**Provide a function name**| Enter `HttpExample`.|
77
77
|**Authorization level**| Choose `Anonymous`, which lets anyone call your function endpoint. For more information about the authorization level, see [Authorization keys](functions-bindings-http-webhook-trigger.md#authorization-keys).|
78
-
|**Select how you would like to open your project**| Choose `Open in current window`.|
79
78
80
79
4. Visual Studio Code uses the provided information and generates an Azure Functions project with an HTTP trigger. You can view the local project files in the Explorer. For more information about the files that are created, see [Generated project files](functions-develop-vs-code.md?tabs=python#generated-project-files).
81
80
::: zone-end
@@ -86,56 +85,21 @@ In this section, you use Visual Studio Code to create a local Azure Functions pr
86
85
|--|--|
87
86
|**Select a language**| Choose `Python (Programming Model V2)`.|
88
87
|**Select a Python interpreter to create a virtual environment**| Choose your preferred Python interpreter. If an option isn't shown, type in the full path to your Python binary.|
89
-
|**Select how you would like to open your project**| Choose `Open in current window`.|
88
+
|**Select a template for your project's first function**| Choose `HTTP trigger`. |
89
+
|**Name of the function you want to create**| Enter `HttpExample`.|
90
+
|**Authorization level**| Choose `ANONYMOUS`, which lets anyone call your function endpoint. For more information about the authorization level, see [Authorization keys](functions-bindings-http-webhook-trigger.md#authorization-keys).|
90
91
91
-
4. Visual Studio Code uses the provided information and generates an Azure Functions project.
92
-
93
-
5. Open the generated `function_app.py` project file, which contains your functions.
94
-
95
-
6. Uncomment the `test_function` function, which is an HTTP triggered function.
96
-
97
-
7. Replace the `app.route()` method call with the following code:
This code enables your HTTP function endpoint to be called in Azure without having to provide an [Authorization keys](functions-bindings-http-webhook-trigger.md#authorization-keys). Local execution doesn't require authorization keys.
104
-
105
-
Your function code should now look like the following example:
logging.info('Python HTTP trigger function processed a request.')
113
-
114
-
name= req.params.get('name')
115
-
ifnot name:
116
-
try:
117
-
req_body= req.get_json()
118
-
exceptValueError:
119
-
pass
120
-
else:
121
-
name= req_body.get('name')
122
-
123
-
if name:
124
-
return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
125
-
else:
126
-
return func.HttpResponse(
127
-
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
128
-
status_code=200
129
-
)
130
-
```
92
+
4. Visual Studio Code uses the provided information and generates an Azure Functions project with an HTTP trigger. You can view the local project files in the Explorer. The generated `function_app.py` project file contains your functions.
131
93
132
-
8. Open the local.settings.json project fileand updated the `AzureWebJobsStorage` setting asin the following example:
94
+
5. 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.
95
+
96
+
6. In the local.settings.json file, update the `AzureWebJobsStorage` setting as in the following example:
This tells the local Functions host to use the storage emulator for the storage connection currently required by the v2 model. When you publish your project to Azure, you'll instead use the default storage account. If you're instead using an Azure Storage account, set your storage account connection string here.
102
+
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.
Copy file name to clipboardExpand all lines: articles/azure-functions/functions-machine-learning-tensorflow.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -111,7 +111,7 @@ In Azure Functions, a function project is a container for one or more individual
111
111
func new --name classify --template "HTTP trigger"
112
112
```
113
113
114
-
This command creates a folder matching the name of the function, *classify*. In that folder are two files: *\_\_init\_\_.py*, which contains the function code, and *function.json*, which describes the function's trigger and its input and output bindings. For details on the contents of these files, see [Examine the file contents](./create-first-function-cli-python.md#optional-examine-the-file-contents) in the Python quickstart.
114
+
This command creates a folder matching the name of the function, *classify*. In that folder are two files: *\_\_init\_\_.py*, which contains the function code, and *function.json*, which describes the function's trigger and its input and output bindings. For details on the contents of these files, see [Programming model](./functions-reference-python.md?pivots=python-mode-configuration#programming-model) in the Python developer guide.
Copy file name to clipboardExpand all lines: articles/azure-functions/machine-learning-pytorch.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -109,7 +109,7 @@ In Azure Functions, a function project is a container for one or more individual
109
109
func new --name classify --template "HTTP trigger"
110
110
```
111
111
112
-
This command creates a folder matching the name of the function, *classify*. In that folder are two files: *\_\_init\_\_.py*, which contains the function code, and *function.json*, which describes the function's trigger and its input and output bindings. For details on the contents of these files, see [Examine the file contents](./create-first-function-cli-python.md#optional-examine-the-file-contents) in the Python quickstart.
112
+
This command creates a folder matching the name of the function, *classify*. In that folder are two files: *\_\_init\_\_.py*, which contains the function code, and *function.json*, which describes the function's trigger and its input and output bindings. For details on the contents of these files, see [Programming model](./functions-reference-python.md?pivots=python-mode-configuration#programming-model) in the Python developer guide.
0 commit comments