Python Azure Function don't load the functions

2025-07-04T14:07:04.33+00:00

I have created an example code that it's not working loading in my azure resource. In local is working fine, but in azure I never see the function running.

User's image

function_app.py

import azure.functions as func 
from src.code import test

app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)

@app.route(route='lts-series')
def GetLTSSeries(req: func.HttpRequest) -> func.HttpResponse:
    return test()

host.json

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[4.*, 5.0.0)"
  }
}

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
    "AzureWebJobsStorage": "UseDevelopmentStorage=true"
  }
}

code.py

def test():
    return "OK"

When I run the local code I see in the cmd:
User's image

But when I upload the code to my function app using this command "func azure functionapp publish myfunctionappname" I never see the function loaded:
User's image

Only if I move the file "code.py" to the root folder and change the import to

from code import test

I'm able to load the function in the Azure resource. I tried a lot of different things, but I don't know what I'm missing.

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

2 answers

Sort by: Most helpful
  1. Alex Burlachenko 18,575 Reputation points Volunteer Moderator
    2025-07-07T08:51:48.6533333+00:00

    Hi Jon Ander,

    check this microsoft doc on python imports in azure functions https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python#folder-structure they explain it well but let me break it down simpler. when u publish to azure, the root folder becomes the base for imports. so if u have a 'src' folder, python might lose its way )) move 'code.py' to the root or tweak the import like u did. but there's a cleaner way!

    in 'function_app.py'

    from .src.code import test  
    

    or add an empty 'init.py' inside 'src' (which u already have, good!)). sometimes python needs that to treat folders as packages. also, check if 'src' is marked as a 'source root' in your ide. this might help in other tools too. if u work with python a lot, worth looking into 'sys.path' tricks. u can dynamically add paths like this

    import sys

    sys.path.append('/path/to/src')

    but yeah, for azure functions, keeping things in the root is the safest bet. as well check this stackoverflow thread https://stackoverflow.com/questions/10253826/path-issue-with-pytest-importerror-no-module-named-yadayadayada its a goldmine for python import quirks.

    dont stress )) python imports are like a box of chocolates... u never know which one will break first :)) https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python#troubleshooting give it a peek...

    hope this helps )) let me know if u need more hints

    Best regards,

    Alex

    and "yes" if you would follow me at Q&A - personaly thx.
    P.S. If my answer help to you, please Accept my answer
    

    https://ctrlaltdel.blog/

    0 comments No comments

  2. Zapirain, Jon Ander (SGRE SE D E2E DS) 0 Reputation points
    2025-07-11T10:49:27.9666667+00:00

    Finally, I resolved the problem, but not easy to see. The problem was when using the command:

    func azure functionapp publish myfunctionappname
    

    It doesn't upload the folders!

    The suggested file structure for Python in Microsoft documentation is to maintain all the files in the root folder... I think it is not a very good solution for a normal application, maybe yes for a "Hello World", but not for a complex application; to maintain all these files could be a nightmare.

    So, to have all my code well distributed in folders with classes, I had to upload the code in ZIP format using the CI/CD Pipelines.

    There is another option, which is to create a ZIP manually with the root folder and upload using the command:

    az functionapp deployment source config-zip -g <resource_group> -n \
    <app_name> --src <zip_file_path>
    
    

Your answer

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