# azure/azure-functions-python-worker architecture

> Architecture diagram of the GitHub repository azure/azure-functions-python-worker, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/azure/azure-functions-python-worker
- Repository: https://github.com/azure/azure-functions-python-worker

## Overview

##### Project type and purpose
- This is an open-source language worker for Azure Functions, written in Python (the “Python Worker”).
- It implements the Functions language‐worker protocol (FunctionRpc) so that the Azure Functions Host (a .NET process) can invoke Python functions, manage triggers/bindings, handle logging, and report cold starts, metrics, etc.

##### File structure
- Top-level modules:
- azure_functions_worker/ – core Python Worker implementation
- protos/ – generated gRPC/Protobuf definitions (FunctionRpc, ClaimsIdentityRpc, NullableTypes)
- extension.py – registers binding extensions
- dispatcher.py – receives host RPCs and routes them to the user function
- loader.py – discovers and loads user code (“Function Apps”)
- bindings/ – converts between gRPC messages and Python types for each binding (Blob, HTTP, Timer, etc.)
- http_v2.py – HTTP v2 streaming support
- utils/ – common helpers (dependency resolution, tracing, app settings)
- main.py – process entry point, starts gRPC server and listens for FunctionRpc calls
- proxy_worker/ – legacy or intermediary layer for some host scenarios (similar structure to azure_functions_worker)
- python/ – sample “worker.config.json” and “worker.py” launch scripts for local or production use
- eng/, .github/, docs/ – CI/CD pipelines, build/release scripts, documentation and templates
- tests/ – split into unit tests, end-to-end tests (triggers, bindings), extension tests, integration tests

##### README for additional insights
- Confirms that the worker hosts Python 3.8–3.12, implements all first-party triggers/bindings, and plugs into Azure Functions Core Tools or VS Code.
- Points to a “Language worker architecture” wiki describing process boundaries, extension loading, and the RPC protocol.

##### Detail
- Every major subcomponent (protos, dispatcher, loader, each binding folder)
- How tests (unit, e2e, extension) map back to modules they cover (e.g., extension_tests → extension.py)
- Do not over-simplify—each binding adapter is a plugin point.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layers
    subgraph "Azure Functions Host" 
        direction TB
        Host("Azure Functions Host (.NET Process)"):::host
    end

    subgraph "Python Worker Process" 
        direction TB
        subgraph "Worker Entry"
            direction TB
            Main["main.py (gRPC Server Entry)"]:::worker
            CLI["__main__.py (CLI Module)"]:::worker
        end
        subgraph "RPC & Protocol"
            direction TB
            Protos["Protobuf Definitions (FunctionRpc, ClaimsIdentityRpc, NullableTypes)"]:::data
        end
        subgraph "Core Components"
            direction TB
            Dispatcher["dispatcher.py (RPC Dispatcher)"]:::worker
            Loader["loader.py (Function Loader)"]:::worker
            ExtensionRegistry["extension.py (Binding Extension Registry)"]:::worker
            BindingAdapters["bindings/ (Binding Adapters)"]:::worker
            HTTPv2["http_v2.py (HTTP v2 Streaming)"]:::worker
            Utils["utils/ (Common Utilities)"]:::module
        end
        subgraph "Legacy Proxy Worker"
            direction TB
            ProxyCore["proxy_worker/"]:::worker
            ProxyDispatcher["proxy_worker/dispatcher.py"]:::worker
            ProxyProtos["proxy_worker/protos/"]:::data
            ProxyUtils["proxy_worker/utils/"]:::module
        end
    end

    subgraph "User Code"
        direction TB
        FunctionApp["Function App Code (userfunctions)"]:::external
    end

    subgraph "Azure Services & External Resources"
        direction TB
        Blob["Blob Storage"]:::external
        CosmosDB["Cosmos DB"]:::external
        EventHub["Event Hub"]:::external
        ServiceBus["Service Bus"]:::external
        HTTPEndpoints["HTTP Endpoints"]:::external
    end

    subgraph "CI/CD & Tooling"
        direction TB
        CoreTools["Azure Functions Core Tools / Docker"]:::ci
        Docs["Documentation & Pipelines"]:::ci
    end

    subgraph "Tests"
        direction TB
        UnitTests["tests/unittests/"]:::test
        ExtensionTests["tests/extension_tests/"]:::test
        EmulatorTests["tests/emulator_tests/"]:::test
        EndToEndTests["tests/endtoend/"]:::test
    end

    %% Connections
    Host -->|"FunctionRpc.Register/Load/Invoke"| Main
    Main -->|loads| Protos
    Main -->|dispatches| Dispatcher
    Dispatcher -->|loads function| Loader
    Loader -->|discovers| FunctionApp
    Loader -->|registers via| ExtensionRegistry
    Dispatcher -->|invokes| FunctionApp
    FunctionApp -->|calls via adapters| BindingAdapters
    ExtensionRegistry -->|provides plugins to| BindingAdapters
    BindingAdapters -->|SDK/REST calls| Blob
    BindingAdapters -->|SDK/REST calls| CosmosDB
    BindingAdapters -->|SDK/REST calls| EventHub
    BindingAdapters -->|SDK/REST calls| ServiceBus
    BindingAdapters -->|HTTP requests| HTTPEndpoints
    Dispatcher -->|logging/tracing| Host

    Host -->|HTTP v2 streaming RPC| HTTPv2
    HTTPv2 -->|routes| Dispatcher

    %% Legacy Proxy flows
    Host -->|alternate integration| ProxyCore
    ProxyCore -->|dispatches| ProxyDispatcher
    ProxyDispatcher -->|uses| ProxyProtos
    ProxyDispatcher -->|utils| ProxyUtils

    %% CI/CD & Tooling
    CoreTools --> Host
    CoreTools --> Main
    Docs --> Host
    Docs --> CLI

    %% Tests coverage
    UnitTests --> Protos
    UnitTests --> Dispatcher
    ExtensionTests --> ExtensionRegistry
    EmulatorTests --> HTTPv2
    EndToEndTests --> FunctionApp

    %% Click Events
    click Protos "https://github.com/azure/azure-functions-python-worker/tree/dev/azure_functions_worker/protos/"
    click ExtensionRegistry "https://github.com/azure/azure-functions-python-worker/blob/dev/azure_functions_worker/extension.py"
    click Dispatcher "https://github.com/azure/azure-functions-python-worker/blob/dev/azure_functions_worker/dispatcher.py"
    click Loader "https://github.com/azure/azure-functions-python-worker/blob/dev/azure_functions_worker/loader.py"
    click BindingAdapters "https://github.com/azure/azure-functions-python-worker/tree/dev/azure_functions_worker/bindings/"
    click HTTPv2 "https://github.com/azure/azure-functions-python-worker/blob/dev/azure_functions_worker/http_v2.py"
    click Utils "https://github.com/azure/azure-functions-python-worker/tree/dev/azure_functions_worker/utils/"
    click Main "https://github.com/azure/azure-functions-python-worker/blob/dev/azure_functions_worker/main.py"
    click CLI "https://github.com/azure/azure-functions-python-worker/blob/dev/azure_functions_worker/__main__.py"
    click ProxyCore "https://github.com/azure/azure-functions-python-worker/tree/dev/proxy_worker/"
    click ProxyDispatcher "https://github.com/azure/azure-functions-python-worker/blob/dev/proxy_worker/dispatcher.py"
    click ProxyProtos "https://github.com/azure/azure-functions-python-worker/tree/dev/proxy_worker/protos/"
    click ProxyUtils "https://github.com/azure/azure-functions-python-worker/tree/dev/proxy_worker/utils/"
    click PythonScripts "https://github.com/azure/azure-functions-python-worker/tree/dev/python/"
    click Docs "https://github.com/azure/azure-functions-python-worker/tree/dev/docs/"
    click CoreTools "https://github.com/azure/azure-functions-python-worker/tree/dev/python/"
    click UnitTests "https://github.com/azure/azure-functions-python-worker/tree/dev/tests/unittests/"
    click ExtensionTests "https://github.com/azure/azure-functions-python-worker/tree/dev/tests/extension_tests/"
    click EmulatorTests "https://github.com/azure/azure-functions-python-worker/tree/dev/tests/emulator_tests/"
    click EndToEndTests "https://github.com/azure/azure-functions-python-worker/tree/dev/tests/endtoend/"

    %% Styles
    classDef host fill:#FFD699,stroke:#CC8400,color:#000;
    classDef worker fill:#C6E2FF,stroke:#5B9BD5,color:#000;
    classDef module fill:#E2F0D9,stroke:#7FB77E,color:#000;
    classDef data fill:#FFE5CC,stroke:#D6913E,color:#000;
    classDef external fill:#F2DCDB,stroke:#C0504D,color:#000;
    classDef ci fill:#E7E6E6,stroke:#7A7A7A,color:#000;
    classDef test fill:#F6DFEB,stroke:#B34176,color:#000;
```
