This is an example repo to demonstrate how to build a Python Worker extension in Azure Functions.
This project framework provides the following features:
- Calculate the time elapsed in every HTTP triggers
- Overwrite the HTTP response from your function to display the elapsed time.
- Python 3.7 or above. To check the full list of supported Python versions in Azure Functions, see the Python developer guide.
- The Azure Functions Core Tools, version 4.0.5095 or later to support v2 Python programming model.
- Visual Studio Code installed on one of the supported platforms.
- Open a Windows PowerShell or any Linux shell as you prefer.
- Change your directory into the
_example/
- Create a Python virtual environment by
py -m venv .venv
in Windows, orpython3 -m venv .venv
in Linux. - Activate the Python virutal environment with
.venv\Scripts\Activate.ps1
in Windows PowerShell orsource .venv/bin/activate
in Linux shell. - Install the packages for your function app project
pip install -r requirements.txt
- Start the function host with
func host start --verbose
You should now be able to access http://localhost:7071/api/HttpTrigger
.
Each http response reports the time elapsed of processing the request.
To install this Python worker extension package in an existing function app:
- Add a VCS URL in your requirements.txt
git+https://github.com/Azure-Samples/python-worker-extension-timer
- Run
pip install -r requirements.txt
- In your FunctionApp/HttpTrigger, add the following lines to enable this feature:
from python_worker_extension_timer import TimerExtension
TimerExtension.configure(append_to_http_response=True)
In the v1 programming model, add the lines in the __init.py__ file. In the v2 programming model, add the lines in the function_app.py file.