Skip to content

Commit b3a06ca

Browse files
authored
Merge pull request #95357 from ggailey777/python
Python 3.7 and other updates
2 parents 27f72aa + 2740607 commit b3a06ca

7 files changed

+152
-128
lines changed

articles/azure-functions/functions-add-output-binding-storage-queue-python.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ You can [examine the Storage queue message](#query-the-storage-queue) again to v
8686

8787
## Next steps
8888

89-
You've updated your HTTP-triggered function to write data to a Storage queue. To learn more about developing Azure Functions with Python, see the [Azure Functions Python developer guide](functions-reference-python.md) and [Azure Functions triggers and bindings](functions-triggers-bindings.md). For examples of complete Function projects in Python, see the [Python Functions samples](/samples/browse/?products=azure-functions&languages=python).
89+
You've updated your HTTP-triggered function to write data to a Storage queue. To learn more about developing Azure Functions with Python, see the [Azure Functions Python developer guide](functions-reference-python.md) and [Azure Functions triggers and bindings](functions-triggers-bindings.md). For examples of complete Function projects in Python, see the [Python Functions samples](/samples/browse/?products=azure-functions&languages=python). To learn more about pricing, see the [Functions pricing page](https://azure.microsoft.com/pricing/details/functions/) and the [Estimating Consumption plan costs](functions-consumption-costs.md) article.
9090

9191
Next, you should enable Application Insights monitoring for your function app:
9292

articles/azure-functions/functions-create-first-function-python.md

Lines changed: 49 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,39 @@ title: Create an HTTP triggered Python function in Azure
33
description: Learn how to create your first Python function in Azure using the Azure Functions Core Tools and the Azure CLI.
44
author: ggailey777
55
ms.author: glenga
6-
ms.date: 09/11/2019
6+
ms.date: 11/07/2019
77
ms.topic: quickstart
88
ms.service: azure-functions
99
ms.custom: mvc
1010
ms.devlang: python
1111
manager: gwallace
1212
---
1313

14-
# Create an HTTP triggered Python function in Azure
14+
# Quickstart: Create an HTTP triggered Python function in Azure
1515

16-
This article shows you how to use command-line tools to create a Python project that runs in Azure Functions. You also create a function that is triggered by an HTTP request. Finally, you publish your project to run as a [serverless function](functions-scale.md#consumption-plan) in Azure.
16+
This article shows you how to use command-line tools to create a Python project that runs in Azure Functions. You also create a function that is triggered by an HTTP request. After running locally, you publish your project to run as a [serverless function](functions-scale.md#consumption-plan) in Azure.
1717

1818
This article is the first of two Python quickstarts for Azure Functions. After you complete this quickstart, you can [add an Azure Storage queue output binding](functions-add-output-binding-storage-queue-python.md) to your function.
1919

20+
There is also a [Visual Studio Code-based version](/azure/python/tutorial-vs-code-serverless-python-01) of this article.
21+
2022
## Prerequisites
2123

2224
Before you start, you must:
2325

24-
+ Install [Python 3.6.8](https://www.python.org/downloads/). This version of Python is verified with Functions. 3.7 and later versions are not yet supported.
26+
+ Install [Python 3.7.4](https://www.python.org/downloads/). This version of Python is verified with Functions. Python 3.8 and later versions are not yet supported.
2527

26-
+ Install [Azure Functions Core Tools](./functions-run-local.md#v2) version 2.7.1575 or a later version.
28+
+ Install [Azure Functions Core Tools](./functions-run-local.md#v2) version 2.7.1846 or a later version.
2729

28-
+ Install the [Azure CLI](/cli/azure/install-azure-cli) version 2.x or a later version.
30+
+ Install the [Azure CLI](/cli/azure/install-azure-cli) version 2.0.76 or a later version.
2931

3032
+ Have an active Azure subscription.
3133

3234
[!INCLUDE [quickstarts-free-trial-note](../../includes/quickstarts-free-trial-note.md)]
3335

34-
## Create and activate a virtual environment (optional)
36+
## Create and activate a virtual environment
3537

36-
You should use a Python 3.6.x environment to locally develop Python functions. Run the following commands to create and activate a virtual environment named `.venv`.
38+
You should use a Python 3.7 environment to locally develop Python functions. Run the following commands to create and activate a virtual environment named `.venv`.
3739

3840
> [!NOTE]
3941
> If Python didn't install venv on your Linux distribution, you can install it using the following command:
@@ -58,111 +60,69 @@ Now that you activated the virtual environment, run the remaining commands in it
5860
5961
## Create a local functions project
6062
61-
A functions project is the equivalent of a function app in Azure. It can have multiple functions that all share the same local and hosting configurations.
63+
A functions project can have multiple functions that all share the same local and hosting configurations.
6264
63-
1. In the virtual environment, run the following command:
65+
In the virtual environment, run the following commands:
6466
65-
```console
66-
func init MyFunctionProj
67-
```
67+
```console
68+
func init MyFunctionProj --python
69+
cd MyFunctionProj
70+
```
6871
69-
1. Select **python** as your worker runtime.
72+
The `func init` command creates a _MyFunctionProj_ folder. The Python project in this folder doesn't yet have any functions. You'll add them next.
7073
71-
The command creates a _MyFunctionProj_ folder. It contains these three files:
74+
## Create a function
7275
73-
* *local.settings.json*: used to store app settings and connection strings when running locally. This file doesn't get published to Azure.
74-
* *requirements.txt*: contains the list of packages the system will install on publishing to Azure.
75-
* *host.json*: contains global configuration options that affect all functions in a function app. This file does get published to Azure.
76+
To add a function to your project, run the following command:
7677
77-
1. Go to the new *MyFunctionProj* folder:
78+
```console
79+
func new --name HttpTrigger --template "HTTP trigger"
80+
```
7881
79-
```console
80-
cd MyFunctionProj
81-
```
82+
This commands creates a subfolder named _HttpTrigger_, which contains the following files:
8283
83-
## Create a function
84+
* *function.json*: configuration file that defines the function, trigger, and other bindings. Notice that in this file, the value for `scriptFile` points to the file containing the function, and the `bindings` array defines the invocation trigger and bindings.
8485
85-
Add a function to the new project.
86+
Each binding requires a direction, type and a unique name. The HTTP trigger has an input binding of type [`httpTrigger`](functions-bindings-http-webhook.md#trigger) and output binding of type [`http`](functions-bindings-http-webhook.md#output).
8687
87-
1. To add a function to your project, run the following command:
88+
* *\_\_init\_\_.py*: script file that is your HTTP triggered function. Notice that this script has a default `main()`. HTTP data from the trigger passes to the function using the `req` named `binding parameter`. The `req`, which is defined in function.json, is an instance of the [azure.functions.HttpRequest class](/python/api/azure-functions/azure.functions.httprequest).
8889
89-
```console
90-
func new
91-
```
90+
The return object, defined as `$return` in *function.json*, is an instance of [azure.functions.HttpResponse class](/python/api/azure-functions/azure.functions.httpresponse). To learn more, see [Azure Functions HTTP triggers and bindings](functions-bindings-http-webhook.md).
9291
93-
1. Use your down-arrow to select the **HTTP trigger** template.
92+
Now you can run the new function on your local computer.
9493
95-
1. When you're prompted for a function name, enter *HttpTrigger* and then press Enter.
94+
## Run the function locally
9695
97-
These commands create a subfolder named _HttpTrigger_. It contains the following files:
96+
This command starts the function app using the Azure Functions runtime (func.exe):
9897
99-
* *function.json*: configuration file that defines the function, trigger, and other bindings. Notice that in this file, the value for `scriptFile` points to the file containing the function, and the `bindings` array defines the invocation trigger and bindings.
98+
```console
99+
func host start
100+
```
100101
101-
Each binding requires a direction, type and a unique name. The HTTP trigger has an input binding of type [`httpTrigger`](functions-bindings-http-webhook.md#trigger) and output binding of type [`http`](functions-bindings-http-webhook.md#output).
102+
You should see the following information written to the output:
102103

103-
* *\_\_init\_\_.py*: script file that is your HTTP triggered function. Notice that this script has a default `main()`. HTTP data from the trigger passes to the function using the `req` named `binding parameter`. The `req`, which is defined in function.json, is an instance of the [azure.functions.HttpRequest class](/python/api/azure-functions/azure.functions.httprequest).
104+
```output
105+
Http Functions:
104106
105-
The return object, defined as `$return` in *function.json*, is an instance of [azure.functions.HttpResponse class](/python/api/azure-functions/azure.functions.httpresponse). To learn more, see [Azure Functions HTTP triggers and bindings](functions-bindings-http-webhook.md).
107+
HttpTrigger: http://localhost:7071/api/HttpTrigger
108+
```
106109

107-
## Run the function locally
110+
Copy the URL of your `HttpTrigger` function from this output and paste it into your browser's address bar. Append the query string `?name=<yourname>` to this URL and execute the request. The following screenshot shows the response to the GET request that the local function returns to the browser:
111+
112+
![Verify locally in the browser](./media/functions-create-first-function-python/function-test-local-browser.png)
113+
114+
Use Ctrl+C to shut down your function app execution.
108115

109-
The function runs locally using the Azure Functions runtime.
110-
111-
1. This command starts the function app:
112-
113-
```console
114-
func host start
115-
```
116-
117-
When the Azure Functions host starts, it writes something like the following output. It's truncated here so you can read it better:
118-
119-
```output
120-
121-
%%%%%%
122-
%%%%%%
123-
@ %%%%%% @
124-
@@ %%%%%% @@
125-
@@@ %%%%%%%%%%% @@@
126-
@@ %%%%%%%%%% @@
127-
@@ %%%% @@
128-
@@ %%% @@
129-
@@ %% @@
130-
%%
131-
%
132-
133-
...
134-
135-
Content root path: C:\functions\MyFunctionProj
136-
Now listening on: http://0.0.0.0:7071
137-
Application started. Press Ctrl+C to shut down.
138-
139-
...
140-
141-
Http Functions:
142-
143-
HttpTrigger: http://localhost:7071/api/HttpTrigger
144-
145-
[8/27/2018 10:38:27 PM] Host started (29486ms)
146-
[8/27/2018 10:38:27 PM] Job host started
147-
```
148-
149-
1. Copy the URL of your `HttpTrigger` function from the runtime output and paste it into your browser's address bar.
150-
151-
1. Append the query string `?name=<yourname>` to this URL and execute the request. The following screenshot shows the response to the GET request that the local function returns to the browser:
152-
153-
![Verify locally in the browser](./media/functions-create-first-function-python/function-test-local-browser.png)
154-
155-
1. Select Ctrl+C to shut down your function app.
156-
157-
Now that you have run your function locally, you can create the function app and other required resources in Azure.
116+
Now that you have run your function locally, you can deploy your function code to Azure.
117+
Before you can deploy your app, you'll need to create some Azure resources.
158118

159119
[!INCLUDE [functions-create-resource-group](../../includes/functions-create-resource-group.md)]
160120

161121
[!INCLUDE [functions-create-storage-account](../../includes/functions-create-storage-account.md)]
162122

163123
## Create a function app in Azure
164124

165-
A function app provides an environment for executing your function code. It lets you group functions as a logical unit for easier management, deployment, and sharing of resources.
125+
A function app provides an environment for executing your function code. It lets you group functions as a logical unit for easier management, deployment, and sharing of resources.
166126

167127
Run the following command. Replace `<APP_NAME>` with a unique function app name. Replace `<STORAGE_NAME>` with a storage account name. The `<APP_NAME>` is also the default DNS domain for the function app. This name needs to be unique across all apps in Azure.
168128

@@ -171,11 +131,11 @@ Run the following command. Replace `<APP_NAME>` with a unique function app name.
171131
172132
```azurecli-interactive
173133
az functionapp create --resource-group myResourceGroup --os-type Linux \
174-
--consumption-plan-location westeurope --runtime python \
134+
--consumption-plan-location westeurope --runtime python --runtime-version 3.7 \
175135
--name <APP_NAME> --storage-account <STORAGE_NAME>
176136
```
177137

178-
The preceding command also provisions an associated Azure Application Insights instance in the same resource group. You can use this instance to monitor your function app and view logs.
138+
The preceding command creates a function app running Python 3.7.4. It also provisions an associated Azure Application Insights instance in the same resource group. You can use this instance to monitor your function app and view logs.
179139

180140
You're now ready to publish your local functions project to the function app in Azure.
181141

@@ -187,7 +147,7 @@ After you create the function app in Azure, you can use the [func azure function
187147
func azure functionapp publish <APP_NAME> --build remote
188148
```
189149

190-
The `--build remote` option builds your Python project remotely in Azure from the files in the deployment package.
150+
The `--build remote` option builds your Python project remotely in Azure from the files in the deployment package, which is recommended.
191151

192152
You'll see output similar to the following message. It's truncated here so you can read it better:
193153

articles/azure-functions/functions-create-function-linux-custom-image.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ You can also use the [Azure Cloud Shell](https://shell.azure.com/bash).
5252

5353
## Create the local project
5454

55-
Run the following command from the command line to create a function app project in the `MyFunctionProj` folder of the current local directory. For a Python project, you [must be running in a virtual environment](functions-create-first-function-python.md#create-and-activate-a-virtual-environment-optional).
55+
Run the following command from the command line to create a function app project in the `MyFunctionProj` folder of the current local directory. For a Python project, you [must be running in a virtual environment](functions-create-first-function-python.md#create-and-activate-a-virtual-environment).
5656

5757
```bash
5858
func init MyFunctionProj --docker

articles/azure-functions/functions-develop-vs-code.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ To run your Functions project locally, you must meet these additional requiremen
272272
| **C#** | [C# extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp)<br/>[.NET Core CLI tools](https://docs.microsoft.com/dotnet/core/tools/?tabs=netcore2x) |
273273
| **Java** | [Debugger for Java extension](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug)<br/>[Java 8](https://aka.ms/azure-jdks)<br/>[Maven 3 or later](https://maven.apache.org/) |
274274
| **JavaScript** | [Node.js](https://nodejs.org/)<sup>*</sup> |
275-
| **Python** | [Python extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python)<br/>[Python 3.6 or later](https://www.python.org/downloads/)|
275+
| **Python** | [Python extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python)<br/>[Python 3.6.8](https://www.python.org/downloads/) recommended|
276276

277277
<sup>*</sup>Active LTS and Maintenance LTS versions (8.11.1 and 10.14.1 recommended).
278278

articles/azure-functions/functions-machine-learning-tensorflow.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ A function app can contain one or more Azure Functions. Open the *start* folder
9696

9797
- [*local.settings.json*](functions-run-local.md#local-settings-file): Contains application settings used for local development
9898
- [*host.json*](functions-host-json.md): Contains settings for the Azure Functions host and extensions
99-
- [*requirements.txt*](functions-reference-python.md#python-version-and-package-management): Contains Python packages required by this application
99+
- [*requirements.txt*](functions-reference-python.md#package-management): Contains Python packages required by this application
100100

101101
## Create an HTTP function
102102

0 commit comments

Comments
 (0)