Skip to content

feat: V2 library worker #1706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 27 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
ignore = W503,E402,E731

exclude = .git, __pycache__, build, dist, .eggs, .github, .local, docs/,
Samples, azure_functions_worker/protos/, proxy_worker/protos/,
azure_functions_worker/_thirdparty/typing_inspect.py,
tests/unittests/test_typing_inspect.py,
tests/unittests/broken_functions/syntax_error/main.py,
.env*, .vscode, venv*, *.venv*
Samples, workers/azure_functions_worker/protos/, workers/proxy_worker/protos/,
workers/azure_functions_worker/_thirdparty/typing_inspect.py,
workers/tests/unittests/test_typing_inspect.py,
workers/tests/unittests/broken_functions/syntax_error/main.py,
.env*, .vscode, venv*, *.venv*,
azure_functions_worker_v2/tests/protos/*,
azure_functions_worker_v2/azure_functions_worker_v2/utils/typing_inspect.py

max-line-length = 88
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,8 @@ prof/
tests/**/host.json
tests/**/bin
tests/**/extensions.csproj

# Azurite related files
__blobstorage__/*
__queuestorage__/*
__azurite*
71 changes: 71 additions & 0 deletions azure_functions_worker_v2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# <img src="https://raw.githubusercontent.com/Azure/azure-functions-python-worker/dev/docs/Azure.Functions.svg" width = "30" alt="Functions Header Image - Lightning Logo"> Azure Functions Python Worker

| Branch | Build Status | CodeCov | Test Status |
|--------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| dev | [![Build Status](https://img.shields.io/azure-devops/build/azfunc/public/658/dev)](https://azfunc.visualstudio.com/public/_build/latest?definitionId=658&branchName=dev) | [![codecov](https://codecov.io/gh/Azure/azure-functions-python-worker/branch/dev/graph/badge.svg)](https://codecov.io/gh/Azure/azure-functions-python-worker) | [![Test Status](https://img.shields.io/azure-devops/build/azfunc/public/658/dev)](https://azfunc.visualstudio.com/public/_build/latest?definitionId=658&branchName=dev) |

Python support for Azure Functions is based on Python 3.13 serverless hosting on Linux and the Functions 4.0 runtime.

Here is the current status of Python in Azure Functions:

What are the supported Python versions?

| Azure Functions Runtime | Python 3.13 |
|----------------------------------|-------------|
| Azure Functions 4.0 | ✔ |

For information about Azure Functions Runtime, please refer to [Azure Functions runtime versions overview](https://docs.microsoft.com/en-us/azure/azure-functions/functions-versions) page.

### What's available?

- Build, test, debug, and publish using Azure Functions Core Tools (CLI) or Visual Studio Code
- Deploy Python Function project onto consumption, dedicated, elastic premium, or flex consumption plan.
- Deploy Python Function project in a custom docker image onto dedicated or elastic premium plan.
- Triggers / Bindings : Blob, Cosmos DB, Event Grid, Event Hub, HTTP, Kafka, MySQL, Queue, ServiceBus, SQL, Timer, and Warmup
- Triggers / Bindings : Custom binding support

### What's new?

- [SDK Type Bindings for Blob](https://techcommunity.microsoft.com/t5/azure-compute-blog/azure-functions-sdk-type-bindings-for-azure-blob-storage-with/ba-p/4146744)
- [HTTP Streaming](https://techcommunity.microsoft.com/t5/azure-compute-blog/azure-functions-support-for-http-streams-in-python-is-now-in/ba-p/4146697)

### Get Started

- [Create your first Python function](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-function-python)
- [Developer guide](https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python)
- [Binding API reference](https://docs.microsoft.com/en-us/python/api/azure-functions/azure.functions?view=azure-python)
- [Develop using VS Code](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-function-vs-code)
- [Create a Python Function on Linux using a custom docker image](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-function-linux-custom-image)

# Give Feedback

Issues and feature requests are tracked in a variety of places. To report this feedback, please file an issue to the relevant repository below:

| Item | Description | Link |
|---------------|----------------------------------------------|--------------------------------------------------------------------------------|
| Python Worker | Programming Model, Triggers & Bindings | [File an Issue](https://github.com/Azure/azure-functions-python-worker/issues) |
| Runtime | Script Host & Language Extensibility | [File an Issue](https://github.com/Azure/azure-functions-host/issues) |
| VSCode | VSCode Extension for Azure Functions | [File an Issue](https://github.com/microsoft/vscode-azurefunctions/issues) |
| Core Tools | Command Line Interface for Local Development | [File an Issue](https://github.com/Azure/azure-functions-core-tools/issues) |
| Templates | Code Issues with Creation Template | [File an Issue](https://github.com/Azure/azure-functions-templates/issues) |

# Contribute

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.microsoft.com.

Here are some pointers to get started:

- [Language worker architecture](https://github.com/Azure/azure-functions-python-worker/wiki/Worker-Architecture)
- [Setting up the development environment](https://github.com/Azure/azure-functions-python-worker/wiki/Contributor-Guide)
- [Adding support for a new binding](https://github.com/Azure/azure-functions-python-worker/wiki/Adding-support-for-a-new-binding-type)
- [Release instructions](https://github.com/Azure/azure-functions-python-worker/wiki/Release-Instructions)

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
13 changes: 13 additions & 0 deletions azure_functions_worker_v2/azure_functions_worker_v2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
from .handle_event import (worker_init_request,
functions_metadata_request,
function_environment_reload_request,
invocation_request,
function_load_request)

__all__ = ('worker_init_request',
'functions_metadata_request',
'function_environment_reload_request',
'invocation_request',
'function_load_request')
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import threading

from .retrycontext import RetryContext
from .tracecontext import TraceContext


class Context:
def __init__(self,
func_name: str,
func_dir: str,
invocation_id: str,
thread_local_storage: threading.local,
trace_context: TraceContext,
retry_context: RetryContext) -> None:
self.__func_name = func_name
self.__func_dir = func_dir
self.__invocation_id = invocation_id
self.__thread_local_storage = thread_local_storage
self.__trace_context = trace_context
self.__retry_context = retry_context

@property
def invocation_id(self) -> str:
return self.__invocation_id

@property
def thread_local_storage(self) -> threading.local:
return self.__thread_local_storage

@property
def function_name(self) -> str:
return self.__func_name

@property
def function_directory(self) -> str:
return self.__func_dir

@property
def trace_context(self) -> TraceContext:
return self.__trace_context

@property
def retry_context(self) -> RetryContext:
return self.__retry_context


def get_context(invoc_request, name: str,
directory: str) -> Context:
""" For more information refer:
https://aka.ms/azfunc-invocation-context
"""
trace_context = TraceContext(
invoc_request.trace_context.trace_parent,
invoc_request.trace_context.trace_state,
invoc_request.trace_context.attributes)

retry_context = RetryContext(
invoc_request.retry_context.retry_count,
invoc_request.retry_context.max_retry_count,
invoc_request.retry_context.exception)

return Context(
name, directory, invoc_request.invocation_id,
threading.local(), trace_context, retry_context)
Loading
Loading