Skip to content

Commit 6041fed

Browse files
authored
feat: V1 library worker (#1719)
* V1 library worker * fix pyproject * apply V2 feedback * fix 313 load request unit test * backport get_origin check fix * fix nullable converters & timestamp * fix mirroring * fix release note * remove pb2_grpc files * misc. cleanup * lib release fix * add back pb2 files * fix v1 __app__ error and remove loader log * flake
1 parent cef88a7 commit 6041fed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+4735
-53
lines changed

.flake8

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ exclude = .git, __pycache__, build, dist, .eggs, .github, .local, docs/,
1212
workers/tests/unittests/broken_functions/syntax_error/main.py,
1313
.env*, .vscode, venv*, *.venv*,
1414
azure_functions_worker_v2/tests/protos/*,
15-
azure_functions_worker_v2/azure_functions_worker_v2/utils/typing_inspect.py
15+
azure_functions_worker_v2/azure_functions_worker_v2/utils/typing_inspect.py,
16+
azure_functions_worker_v1/tests/protos/*,
17+
azure_functions_worker_v1/azure_functions_worker_v1/utils/typing_inspect.py
1618

17-
max-line-length = 88
19+
max-line-length = 88

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,4 @@ tests/**/extensions.csproj
136136
# Azurite related files
137137
__blobstorage__/*
138138
__queuestorage__/*
139-
__azurite*
139+
__azurite*
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# <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
2+
3+
| Branch | Build Status | CodeCov | Test Status |
4+
|--------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
5+
| 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) |
6+
7+
Python support for Azure Functions is based on Python 3.13 serverless hosting on Linux and the Functions 4.0 runtime.
8+
9+
Here is the current status of Python in Azure Functions:
10+
11+
What are the supported Python versions?
12+
13+
| Azure Functions Runtime | Python 3.13 |
14+
|----------------------------------|-------------|
15+
| Azure Functions 4.0 ||
16+
17+
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.
18+
19+
### What's available?
20+
21+
- Build, test, debug, and publish using Azure Functions Core Tools (CLI) or Visual Studio Code
22+
- Deploy Python Function project onto consumption, dedicated, elastic premium, or flex consumption plan.
23+
- Deploy Python Function project in a custom docker image onto dedicated or elastic premium plan.
24+
- Triggers / Bindings : Blob, Cosmos DB, Event Grid, Event Hub, HTTP, Kafka, MySQL, Queue, ServiceBus, SQL, Timer, and Warmup
25+
- Triggers / Bindings : Custom binding support
26+
27+
### What's new?
28+
29+
- [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)
30+
- [HTTP Streaming](https://techcommunity.microsoft.com/t5/azure-compute-blog/azure-functions-support-for-http-streams-in-python-is-now-in/ba-p/4146697)
31+
32+
### Get Started
33+
34+
- [Create your first Python function](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-function-python)
35+
- [Developer guide](https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python)
36+
- [Binding API reference](https://docs.microsoft.com/en-us/python/api/azure-functions/azure.functions?view=azure-python)
37+
- [Develop using VS Code](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-function-vs-code)
38+
- [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)
39+
40+
# Give Feedback
41+
42+
Issues and feature requests are tracked in a variety of places. To report this feedback, please file an issue to the relevant repository below:
43+
44+
| Item | Description | Link |
45+
|---------------|----------------------------------------------|--------------------------------------------------------------------------------|
46+
| Python Worker | Programming Model, Triggers & Bindings | [File an Issue](https://github.com/Azure/azure-functions-python-worker/issues) |
47+
| Runtime | Script Host & Language Extensibility | [File an Issue](https://github.com/Azure/azure-functions-host/issues) |
48+
| VSCode | VSCode Extension for Azure Functions | [File an Issue](https://github.com/microsoft/vscode-azurefunctions/issues) |
49+
| Core Tools | Command Line Interface for Local Development | [File an Issue](https://github.com/Azure/azure-functions-core-tools/issues) |
50+
| Templates | Code Issues with Creation Template | [File an Issue](https://github.com/Azure/azure-functions-templates/issues) |
51+
52+
# Contribute
53+
54+
This project welcomes contributions and suggestions. Most contributions require you to agree to a
55+
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
56+
the rights to use your contribution. For details, visit https://cla.microsoft.com.
57+
58+
Here are some pointers to get started:
59+
60+
- [Language worker architecture](https://github.com/Azure/azure-functions-python-worker/wiki/Worker-Architecture)
61+
- [Setting up the development environment](https://github.com/Azure/azure-functions-python-worker/wiki/Contributor-Guide)
62+
- [Adding support for a new binding](https://github.com/Azure/azure-functions-python-worker/wiki/Adding-support-for-a-new-binding-type)
63+
- [Release instructions](https://github.com/Azure/azure-functions-python-worker/wiki/Release-Instructions)
64+
65+
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
66+
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
67+
provided by the bot. You will only need to do this once across all repos using our CLA.
68+
69+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
70+
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
71+
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
from .handle_event import (worker_init_request,
5+
functions_metadata_request,
6+
function_environment_reload_request,
7+
invocation_request,
8+
function_load_request)
9+
10+
__all__ = ('worker_init_request',
11+
'functions_metadata_request',
12+
'function_environment_reload_request',
13+
'invocation_request',
14+
'function_load_request')
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import threading
5+
6+
from typing import Type
7+
8+
from .retrycontext import RetryContext
9+
from .tracecontext import TraceContext
10+
11+
12+
class Context:
13+
def __init__(self,
14+
func_name: str,
15+
func_dir: str,
16+
invocation_id: str,
17+
thread_local_storage: Type[threading.local],
18+
trace_context: TraceContext,
19+
retry_context: RetryContext) -> None:
20+
self.__func_name = func_name
21+
self.__func_dir = func_dir
22+
self.__invocation_id = invocation_id
23+
self.__thread_local_storage = thread_local_storage
24+
self.__trace_context = trace_context
25+
self.__retry_context = retry_context
26+
27+
@property
28+
def invocation_id(self) -> str:
29+
return self.__invocation_id
30+
31+
@property
32+
def thread_local_storage(self) -> Type[threading.local]:
33+
return self.__thread_local_storage
34+
35+
@property
36+
def function_name(self) -> str:
37+
return self.__func_name
38+
39+
@property
40+
def function_directory(self) -> str:
41+
return self.__func_dir
42+
43+
@property
44+
def trace_context(self) -> TraceContext:
45+
return self.__trace_context
46+
47+
@property
48+
def retry_context(self) -> RetryContext:
49+
return self.__retry_context
50+
51+
52+
def get_context(invoc_request, name: str,
53+
directory: str) -> Context:
54+
""" For more information refer:
55+
https://aka.ms/azfunc-invocation-context
56+
"""
57+
trace_context = TraceContext(
58+
invoc_request.trace_context.trace_parent,
59+
invoc_request.trace_context.trace_state,
60+
invoc_request.trace_context.attributes)
61+
62+
retry_context = RetryContext(
63+
invoc_request.retry_context.retry_count,
64+
invoc_request.retry_context.max_retry_count,
65+
invoc_request.retry_context.exception)
66+
67+
return Context(
68+
name, directory, invoc_request.invocation_id,
69+
threading.local(), trace_context, retry_context)

0 commit comments

Comments
 (0)