Azure Functions language workers are responsible for indexing, dependency management, invocations and status for all the code you write within Functions. With Rust, major pieces of the worker can now be performant, while keeping the existing behavior intact.
When you write a Python function, your focus is on what the function should do. Behind the scenes, the layer that passes requests to your code affects dependency compatibility, support for new Python versions, and performance.
As we started working on Python 3.15 support for Azure Functions, we took another look at that layer. Our goal was to move host communication away from Python transport packages while keeping the code that runs functions in Python.
The result is R2P2, short for Rust to Python Proxy. Its communication layer is written in Rust, and your functions still run in Python. Here's what we changed, why we chose Rust, and what we learned along the way.
How a Python function gets to work
Azure Functions lets you run code in response to events, such as an HTTP request, a message in a queue, or a file upload. Two components work together to get that event to your code:
- The Functions host listens for events and sends work to the appropriate language worker.
- The Python worker loads and calls your Python function, then sends the result and logs back to the host.
The worker for Python 3.13 and 3.14 already split that work into two layers. A Python-based proxy worker, an intermediary inside the worker process, handled communication with the host. It then passed requests to the Python runtime libraries, which discover functions, prepare their inputs, and invoke them. Here, runtime libraries mean the worker's Python execution code, rather than a separate service.
Python 3.13 and 3.14: the host communicates with a Python proxy, which calls the runtime libraries. The proxy and application share an interpreter.
That split gave us a place to make a focused change. We could build a new communication layer while keeping the Python runtime libraries.
What changed, and what stayed Python
R2P2 builds on architectural decisions made over several Python releases. With Python 3.13, we introduced the proxy workerand separated communication with the host from the libraries that execute functions. That gave each layer a clearer responsibility and allowed the Python execution libraries to evolve separately from the transport.
That earlier work made this change practical. For Python 3.15, we had an established boundary where we could replace the Python proxy with a Rust transport while retaining the Python execution libraries. The work involved adapting the runtime integration, handling the Rust-to-Python handoff, and validating startup, imports, and function execution together. It was an evolution of the worker architecture, built on the separation introduced in Python 3.13.
With R2P2, the host uses the same protocol as before, but a Rust transport layer, the part that sends and receives messages, handles the communication. PyO3 connects it to an embedded CPython interpreter, the Python interpreter running inside the worker process, and the existing Python execution libraries.
Python 3.15 and R2P2: Rust replaces the Python transport. The bridge and Python execution libraries run in the same worker process.
We adapted the integration with the runtime libraries and kept Python responsible for function execution. Users continue to write Python functions using the same programming models.
For a deeper look at how the worker fits together, see the Python worker architecture documentation.
Why consider Rust?
We wanted the worker's communication stack to use a different set of dependencies while preserving the Python execution layer. Rust gave us a way to do both.
- A communication stack independent of Python packages: The Python proxy used grpcio for gRPC, the protocol the host and worker use to communicate, and protobuf to encode and decode their messages. These packages include native components, so a new Python version or platform needs compatible package builds. They also share an interpreter with your application, which might need different versions of those packages.
Moving that layer to Rust let us use tonic for gRPC and prost for Protocol Buffers. The host still speaks the same protocol, while the worker uses a Rust implementation. Your application can continue to use Python's grpcio and protobuf packages; the worker's transport uses its own Rust libraries for communication. - A practical bridge back to Python: We also needed a practical way for Rust to call the existing Python execution libraries. PyO3 gave us that connection. It provided the capabilities we needed to integrate a Rust transport with the existing worker’s Python execution libraries: embedding CPython, calling Python code, and passing values between the two languages.
That let us build on the Python execution layer we already had. Through PyO3, the Rust transport calls those libraries within the same worker process, and they continue to load and run your Python functions.
What this enables
Changing the transport gives us a few benefits:
- A shorter path to supporting new Python versions: The worker's communication layer can be built for a new Python release independently of compatible Python grpcio and protobuf packages. Using tonic and prost removes that transport-package gate from the process. We still build against the new interpreter and validate the execution libraries, tooling, and application compatibility. Removing a dependency from that process gives us more control over the path to a new Python release.
- Separate transport dependencies from application packages: The Rust transport uses its own libraries for messaging. An application can choose the Python grpcio and protobuf packages it needs without competing with the worker's transport for those imports. That removes one source of dependency collisions: the worker transport and application needing different versions. Compatibility between an application's own dependencies remains something to manage.
- Windows ARM64 support in the Azure Functions CLI: The Azure Functions CLI (v5) lets users run and test functions locally. Python support on Windows ARM64 depended in part on the availability of Python's gRPC package, grpcio for that platform. Moving the worker's transport to Rust removes that dependency and helps enable Python support on Windows ARM64 in the Azure Functions CLI (v5).
- Performance as an added benefit: Every request needs work before and after your function runs. The worker receives and decodes a message, routes it, and sends the response back. For a short function, that overhead can make up a meaningful part of the request.
Rust lets us handle that communication natively and keep it moving while Python runs a function. In our performance testing, Python 3.15 with R2P2 delivered about 50% higher throughput than Python 3.14. The comparison includes both a Python version change and a worker change, so it measures the combined result rather than Rust's contribution alone.
What we learned
- Start with a boundary: The split between the proxy and execution libraries gave us a clear place to start. We could focus on how the worker receives and sends messages while keeping the existing Python code for function discovery, bindings, and invocation.
That boundary helped us keep the project manageable. We could test whether the Rust transport worked with the behavior the Python runtimes already provided, instead of rebuilding that behavior in another language. We still had integration work to do, especially where messages and function inputs cross from one side to the other. - The handoff has a cost: A request crosses several steps on its way from the host to your function. Rust receives and decodes the host's message, then passes the values Python needs to the execution layer. The result takes the return journey. Each conversion between Rust and Python has a cost, particularly for functions that do very little work themselves.
We learned to look at the whole request path when evaluating performance. Faster message handling is useful, but the data passed across the bridge and the work done on either side matter too. Rust can keep communication moving while Python runs a function; Python execution still follows the standard interpreter's concurrency constraints. - Rust has a learning curve: Rust asks you to think explicitly about ownership: which part of the program is responsible for a value, how long it lives, and who can use it. Coming from Python, that took some adjustment. The questions became especially important at the bridge, where Rust code interacts with objects managed by the Python interpreter and work may arrive concurrently.
The compiler gives useful feedback while we build, and that helped us reason about how data is shared. It also took time to learn how to express those relationships. Debugging can now involve both Rust and Python, and the interpreter and its native extensions still need their own testing. The learning continues beyond getting the code to compile. - Startup and imports need attention: Getting a request through a running worker is one part of the job. At startup, the worker also needs to find the application, select the appropriate Python execution layer, and load dependencies in the expected order. Those steps matter because applications may bring packages that overlap with packages used by the worker.
Shared Python namespaces were a useful example. Several packages can contribute modules under the same namespace. When dependency paths change, Python may still have earlier imports cached. The worker needs to account for both the paths and the loaded modules so subsequent imports find the right code.
That work made the boundary more than a function call. Startup, imports, and the way the worker is packaged all contribute to a reliable experience.
The trade-offs
We now maintain a mixed-language worker, build native binaries for supported platforms, and test the Rust-to-Python boundary. Troubleshooting can involve both toolchains. Startup, imports, and packaging all need attention as the worker evolves.
For us, those costs were worth taking on to address the transport dependencies while keeping the Python execution layer. This boundary gave us a place to use Rust for communication and Python for running the functions users write.