Skip to content

Commit 2791835

Browse files
authored
Merge pull request #232790 from vmagelo/freshness-work3
Freshness pass.
2 parents 143d4ef + 73c049e commit 2791835

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

articles/azure-functions/develop-python-worker-extensions.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
title: Develop Python worker extensions for Azure Functions
33
description: Learn how to create and publish worker extensions that let you inject middleware behavior into Python functions running in Azure.
44
ms.topic: how-to
5-
ms.date: 6/1/2021
5+
ms.date: 04/13/2023
66
ms.custom: devx-track-python, py-fresh-zinc
77
---
88

99
# Develop Python worker extensions for Azure Functions
1010

11-
Azure Functions lets you integrate custom behaviors as part of Python function execution. This feature enables you to create business logic that customers can easily use in their own function apps. To learn more, see the [Python developer reference](functions-reference-python.md#python-worker-extensions).
11+
Azure Functions lets you integrate custom behaviors as part of Python function execution. This feature enables you to create business logic that customers can easily use in their own function apps. To learn more, see the [Python developer reference](functions-reference-python.md#python-worker-extensions). Worker extensions are supported in both the v1 and v2 Python programming models.
1212

1313
In this tutorial, you'll learn how to:
1414
> [!div class="checklist"]
@@ -20,9 +20,9 @@ In this tutorial, you'll learn how to:
2020

2121
Before you start, you must meet these requirements:
2222

23-
* [Python 3.6.x or above](https://www.python.org/downloads/release/python-374/). To check the full list of supported Python versions in Azure Functions, see the [Python developer guide](functions-reference-python.md#python-version).
23+
* [Python 3.7 or above](https://www.python.org/downloads). To check the full list of supported Python versions in Azure Functions, see the [Python developer guide](functions-reference-python.md#python-version).
2424

25-
* The [Azure Functions Core Tools](functions-run-local.md#v2), version 3.0.3568 or later.
25+
* The [Azure Functions Core Tools](functions-run-local.md#v2), version 4.0.5095 or later, which supports using the extension with the [v2 Python programming model](./functions-reference-python.md). Check your version with `func --version`.
2626

2727
* [Visual Studio Code](https://code.visualstudio.com/) installed on one of the [supported platforms](https://code.visualstudio.com/docs/supporting/requirements#_platforms).
2828

@@ -48,7 +48,7 @@ The folder for your extension project should be like the following structure:
4848
| **.venv/** | (Optional) Contains a Python virtual environment used for local development. |
4949
| **python_worker_extension/** | Contains the source code of the Python worker extension. This folder contains the main Python module to be published into PyPI. |
5050
| **setup.py** | Contains the metadata of the Python worker extension package. |
51-
| **readme.md** | (Optional) Contains the instruction and usage of your extension. This content is displayed as the description in the home page in your PyPI project. |
51+
| **readme.md** | Contains the instruction and usage of your extension. This content is displayed as the description in the home page in your PyPI project. |
5252

5353
### Configure project metadata
5454

@@ -76,6 +76,19 @@ The `pre_invocation_app_level` method is called by the Python worker before the
7676

7777
Similarly, the `post_invocation_app_level` is called after function execution. This example calculates the elapsed time based on the start time and current time. It also overwrites the return value of the HTTP response.
7878

79+
### Create a readme.md
80+
81+
Create a readme.md file in the root of your extension project. This file contains the instructions and usage of your extension. The readme.md content is displayed as the description in the home page in your PyPI project.
82+
83+
```markdown
84+
# Python Worker Extension Timer
85+
86+
In this file, tell your customers when they need to call `Extension.configure()`.
87+
88+
The readme should also document the extension capabilities, possible configuration,
89+
and usage of your extension.
90+
```
91+
7992
## Consume your extension locally
8093

8194
Now that you've created an extension, you can use it in an app project to verify it works as intended.
@@ -135,7 +148,8 @@ Now that you've created an extension, you can use it in an app project to verify
135148
pip install -e <PYTHON_WORKER_EXTENSION_ROOT>
136149
```
137150

138-
In this example, replace `<PYTHON_WORKER_EXTENSION_ROOT>` with the file location of your extension project.
151+
In this example, replace `<PYTHON_WORKER_EXTENSION_ROOT>` with the root file location of your extension project.
152+
139153
When a customer uses your extension, they'll instead add your extension package location to the requirements.txt file, as in the following examples:
140154
141155
# [PyPI](#tab/pypi)
@@ -159,7 +173,7 @@ Now that you've created an extension, you can use it in an app project to verify
159173
160174
When running in Azure, you instead add `PYTHON_ENABLE_WORKER_EXTENSIONS=1` to the [app settings in the function app](functions-how-to-use-azure-function-app-settings.md#settings).
161175
162-
1. Add following two lines before the `main` function in \_\_init.py\_\_:
176+
1. Add following two lines before the `main` function in *\_\_init.py\_\_* file for the v1 programming model, or in the *function_app.py* file for the v2 programming model:
163177
164178
```python
165179
from python_worker_extension_timer import TimerExtension
@@ -174,9 +188,9 @@ Now that you've created an extension, you can use it in an app project to verify
174188
175189
1. In the browser, send a GET request to `https://localhost:7071/api/HttpTrigger`. You should see a response like the following, with the **TimeElapsed** data for the request appended.
176190
177-
<pre>
191+
```
178192
This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response. (TimeElapsed: 0.0009996891021728516 sec)
179-
</pre>
193+
```
180194
181195
## Publish your extension
182196
@@ -211,7 +225,7 @@ To publish your extension to PyPI:
211225
twine upload dist/*
212226
```
213227

214-
You may need to provide your PyPI account credentials during upload.
228+
You may need to provide your PyPI account credentials during upload. You can also test your package upload with `twine upload -r testpypi dist/*`. For more information, see the [Twine documentation](https://twine.readthedocs.io/en/stable/).
215229

216230
After these steps, customers can use your extension by including your package name in their requirements.txt.
217231

0 commit comments

Comments
 (0)