Execute python code through azure function app in vscode

Kumar, Arun 296 Reputation points
2023-05-30T21:32:00.9266667+00:00

Hi,

I have a pyspark code (casings.py) that calls a REST API does pagination and generates output in blob container in the form of delta parquet. I can execute this in a notebook and it runs fine generating output.

I need to execute the same code using a function app which will be called in the pipeline. To create a function app and execute it locally before publishing to Azure, i used vscode to create a project and generated all the associated files like function.json, hosts.json, init.py, requirements.txt etc like how it was shown in the microsoft learn site. But i am not able to find a way to call my python code casings.py. I searched everywhere and could find only examples of httptrigger, which is very basic. Can i just copy paste the python code in init.py and publish the function app? Or does it needs to be called from init.py?

Any tutorial or pointers that provides info on how to call a python code using a function would be helpful

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,322 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,959 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 26,146 Reputation points Microsoft Employee
    2023-06-01T23:15:51.6766667+00:00

    Hi @Kumar, Arun

    Azure Functions Python developer guide is the documentation you're looking for. But you do have a couple of options.

    • You can adjust the scriptFile in function.json to point to casings.py. You will need to make sure you have so that your function can trigger (make sure you adjust the function for any bindings you may have).
    import azure.functions
    
    def main(req: azure.functions.HttpRequest) -> str:
        user = req.params.get('user')
        return f'Hello, {user}!'
    
    • Reference casings.py from __init__.py via import * from casings and your function(s) inside your trigger.