How to share code over multiple function apps? (PYTHON)

Giel Oomen 36 Reputation points
2025-07-04T15:10:10.93+00:00

What is the recommended way to reuse the same code between multiple function apps without having to go through a lot of ugly steps to make deployment work?

I have a directory setup which is super simple to test and verify this concept:

  • workspace
    • func_app_one
    • func_app_two
    • shared_code

In both func_app_one and func_app_two I want to use shared_code which while running Python files is no problem at all. However, how am I supposed to deploy this to my Azure Function Apps?

Deploying through the vscode extension doesn't work because it only deploys the root dir of one of the function apps so shared_code will be missing.

A local docker build also does not work, because the shared_code will be missing.

What does work is using symbolic links inside func_app_one and two HOWEVER this means every file shows up three times in the IDE and this will get worse as more services must share this same code. Also this is an incredibly ugly workaround.

What also work is moving files around, changing code during build to sort of bend the directory so the structure changes to work with deployments, this is worse than symlinks.

Creating a package and uploading it to pypi or git and make it accessible by the function app to install in the cloud will probably work but that's a lot of extra work which also does not make sense to go through.

Am I missing something here? This is a really basic setup, I have read tens of posts from others with the same problem but yet there is not one clean implementation. Any suggestions are greatly appreciated.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,940 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sai Prabhu Naveen Parimi 2,590 Reputation points Microsoft External Staff Moderator
    2025-07-04T16:49:34.1966667+00:00

    @Giel Oomen

    It looks like you're trying to figure out a clean way to share code between multiple Azure Function Apps without all the hassle of deploying duplicate files or using symlinks. Here are a couple of strategies you can consider:

    Monorepo Structure: Instead of separate directories for each function app, you could structure your project as a monorepo where both function apps and shared code coexist. You would then create a deployment package that includes both function apps and the shared code directory. This way, everything is part of the same project, and you can deploy it all at once.

    Using Zip Deployment with Shared Code: As mentioned in the relevant documentation, you can create a zip package that encapsulates your entire project, including the shared code. When you deploy using the Azure CLI with the --build-remote flag, it might help in correctly deploying the structure you need. Your zip file would look something like this:

    workspace.zip/
    |-- func_app_one/
    |   |-- __init__.py
    |   |-- function.json
    |   |-- your_function_file.py
    |-- func_app_two/
    |   |-- __init__.py
    |   |-- function.json
    |   |-- your_other_function_file.py
    |-- shared_code/
    |   |-- __init__.py
    |   |-- shared_util.py
    

    Packaging as a Library: If the shared code is significant and reused frequently, consider packaging it as a Python module. You can install it via pip from a private PyPi server or even directly from a GitHub repo. This way, your function apps can have a clean import statement like from shared_code import my_function.

    Use Azure Storage for Shared Code: Another approach is to store the shared code in Azure Blob Storage and download it into each function app at runtime. You'd have to handle the downloading and importing logic but it could keep your directory clean.

    Deploy with Azure Functions CI/CD: Utilize CI/CD pipelines to build and package your application for each function app while ensuring that the shared code is included as well.

    Hope this gives you some useful ideas!


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.