Use binding extension in code in Azure Functions (Python V2)

Dhruv Singla 150 Reputation points
2025-07-01T18:52:49.9233333+00:00

As shown here, the trigger file name can be used as an expression inside the code.

// C# example of binding to {filename}
public static void Run(Stream image, string filename, Stream imageSmall, ILogger log)  
{
    log.LogInformation($"Blob trigger processing: {filename}");
    // ...
}

I tried doing the same in Python

import azure.functions as func
import logging

app = func.FunctionApp()

@app.blob_trigger(arg_name="myblob", path="%code_env%/src/{filename}.txt",
                               connection="storagetriggerfunc_STORAGE") 
def blob_trigger(myblob: func.InputStream, filename: str):
    logging.info(f"Python blob trigger function processed blob"
                f"Name: {myblob.name}"
                f"Blob Size: {myblob.length} bytes")

But got the following error

Worker failed to index functions
Result: Failure
Exception: FunctionLoadError: cannot load the blob_trigger function: the following parameters are declared in Python but not in function.json: {'filename'}

How to do it correctly in python? I don't want to know about the name attribute of the first argument.

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

Accepted answer
  1. Marcin Policht 51,450 Reputation points MVP Volunteer Moderator
    2025-07-01T19:23:05.4433333+00:00

    In Python Azure Functions, binding expressions like {filename} in the path work differently compared to C#. The binding expressions can be used, but they are not automatically available as function parameters (unlike in C#). You can use {filename} in the path of your blob trigger binding. However, you cannot add filename as a separate parameter to the function. Instead, you should access it from the myblob.name property and parse it manually.

    Try the following:

    import azure.functions as func
    import logging
    import os
    
    app = func.FunctionApp()
    
    @app.blob_trigger(arg_name="myblob", path="%code_env%/src/{filename}.txt",
                      connection="storagetriggerfunc_STORAGE") 
    def blob_trigger(myblob: func.InputStream):
        # Full blob name (path + filename)
        blob_name = myblob.name  # e.g., "container/src/foo.txt"
    
        # Extract filename from the blob name
        filename = os.path.basename(blob_name)  # "foo.txt"
    
        logging.info(f"Python blob trigger processed blob")
        logging.info(f"Name: {filename}")
        logging.info(f"Blob Size: {myblob.length} bytes")
    
    • myblob.name: gives you the full path to the blob (including container name).
    • os.path.basename(...): extracts just the {filename}.txt part from the path.

    The following is invalid because Python Azure Functions does not support direct binding of path parameters to function arguments like C# does.

    def blob_trigger(myblob: func.InputStream, filename: str): 
    

    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    0 comments No comments

0 additional answers

Sort by: Most helpful

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.