[Python] Sharing package within a Python project with Azure Functions

Discussão em 'Python' iniciado por Stack, Setembro 9, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to reuse some code within my python project, within an Azure Function, it is structured as follows:

    myproject/
    | - a_app/
    | - b_app/
    | - c_lib/
    | - requirements.txt


    Up until now I have been conveniently avoiding sharing code between my 2 separate modules a_app and b_app. But I now want to create some classes that I can share and place it within c_lib.

    I have an Azure function here:

    myproject/
    | - a_app/FunctionA/init.py


    It is referencing the library c_lib by importing using the following statement: from c_lib.foundation_utility.jwt_enforced_permissions import JWTEnforcedPermissions

    All the tests pass locally and the reference is imported successfully but when I deploy to my Azure Function it simply can't find the library (an example class I'm trying to share):

    File "/home/site/wwwroot/FunctionA/init.py", line 10, in from c_lib.foundation_utility.jwt_enforced_permissions import JWTEnforcedPermissions File "/home/site/wwwroot/c_lib/foundation_utility/jwt_enforced_permissions.py", line 4, in from foundation_utility.i_token_permissions import ITokenPermissions

    For the life of me I can't figure out why it can't find the library. I am trying to browser the Azure Function folder structure so that I can figure out where the file is actually located to reconcile why it's not working.

    Given that I have been able to reference various classes within my a_app and b_app respectfully, but not referencing one another, I know how to successfully call the right namespace. I therefore thought about copying the c_lib into the folders of a_app/ and b_app/ respectfully as part of a github build action:

    - name: Copy c_lib into Function App Directory
    run: |
    cp -r c_lib a_app/


    However despite doing this and trying to reference c_lib from within a_app it still not working. I also considered creating this library as a pip module, but that's not what I'm looking for as I want to deploy the library as the same version as a_app and b_app. I don't want version invariance.

    Something about the Azure Function means that it can't access code beyond its own package.

    Continue reading...

Compartilhe esta Página