FunctionApp

class FunctionApp(app_name)

This class represents a Functions application. It provides the ability to register routes using the route() method and other triggers

app_name The name of the Functions app. This corresponds to the value provided when instantiating a functions object.

Route (HTTP Trigger)

route(path, **options)

Register a http trigger for a particular URI path. This method is to be used as a decorator. For example:

from azure.functions import FunctionApp

app = FunctionApp(app_name="appname")

@app.route('/helloworld/{value}', methods=['PUT'],
            auth_level="anonymous", param_name="request")
def hello(request):
    pass

Parameters:

  • str path: The path to associate with the view function. The path should only contain [a-zA-Z0-9._-] chars and curly braces for parts of the URL you would like to capture. The path should not end in a trailing slash.

  • str param_name: The variable name used in function code that represents Function.request

  • list methods: parameter that indicates which HTTP methods this function should accept. By default, only GET requests are supported. If you only wanted to support POST requests, you would specify methods=['POST']. If you support multiple HTTP methods in a single function (methods=['GET', 'POST'])

  • AuthLevel auth_level: Determines what keys, if any, need to be present on the request in order to invoke the function. The authorization level can be one of the following values:

  • anonymous — No API key is required.
  • function — A function-specific API key is required. This is the default value if none is provided.
  • admin — The master key is required

Schedule (Timer Trigger)

Create a function that’s invoked on a regular schedule.

schedule(expression, param_name, **options)

example:

@app.schedule(expression="* * * 5 *", param_name="timer_context" )
def cron_handler(timer_context):
    pass

Parameters:

  • str expression: A CRON expression that represents the time interval in which the function will be invoked

  • str param_name: The variable name used in function code that represents Timer context.

Azure Blob Trigger

on_blob_change(path: str, connection_string: str, param_name: str)

Register a function to be triggered when a new or updated Azure Blob Storage is detected. This method is to be used as a decorator. For example:

@app.on_blob_change(path="my_containter", connection_string="MyStorageAccount", 
                    param_name="blob_input")
def blob_handler(blob_input):
    pass

Parameters:

  • str path: Path to the container to monitor in Azure Blob Storage. May be a blob name pattern.

  • str connection_string: The name of an app setting that contains the Storage connection string to use for this binding. If the app setting name begins with "AzureWebJobs", you can specify only the remainder of the name here. For example, if you set connection to "MyStorage", the Functions runtime looks for an app setting that is named "AzureWebJobsMyStorage." If you leave connection empty, the Functions runtime uses the default Storage connection string in the app setting that is named AzureWebJobsStorage.

  • str param_name: The name of the variable that represents the blob in function code

Blob input binding

read_blob(path: str, connection_string: str, data_type: str, param_name: str)

Add a Azure Blob Storage input binding to a function.The input binding allows you to read blob storage data as input to an Azure Function.

@app.read_blob(path="my_containter", connection_string="MyStorageAccount", 
                    data_type="binary", param_name="blob_input")
@app.route('/read_blob', methods=['GET'],
            auth_level="anonymous", param_name="request")
def blob_handler(request, blob_input):
    pass

Parameters:

  • str path : Path to the container to monitor in Azure Blob Storage. May be a blob name pattern.

  • str connection_string : The name of an app setting that contains the Storage connection string to use for this binding. If the app setting name begins with "AzureWebJobs", you can specify only the remainder of the name here. For example, if you set connection to "MyStorage", the Functions runtime looks for an app setting that is named "AzureWebJobsMyStorage." If you leave connection empty, the Functions runtime uses the default Storage connection string in the app setting that is named AzureWebJobsStorage.

  • str data_type : data_type specifies the underlying data type. Possible values are string, binary, or stream

  • str param_name : The name of the variable that represents the blob in function code

Blob output binding

def write_blob(path: str, connection_string: str, param_name: str):

Add a Azure Blob Storage output binding to a function. The output binding allows you to qrite data to blob storage.

@app.write_blob(path="my_containter", connection_string="MyStorageAccount", 
                    data_type="binary", param_name="blob_output")
@app.route('/read_blob', methods=['GET'],
            auth_level="anonymous", param_name="request")
def blob_handler(request, blob_output):
    pass

Parameters:

  • str path : Path to the container to monitor in Azure Blob Storage. May be a blob name pattern.

  • str connection_string : The name of an app setting that contains the Storage connection string to use for this binding. If the app setting name begins with "AzureWebJobs", you can specify only the remainder of the name here. For example, if you set connection to "MyStorage", the Functions runtime looks for an app setting that is named "AzureWebJobsMyStorage." If you leave connection empty, the Functions runtime uses the default Storage connection string in the app setting that is named AzureWebJobsStorage.

  • str data_type : data_type specifies the underlying data type. Possible values are string, binary, or stream

  • str param_name : The name of the variable that represents the blob in function code

Azure Table Input binding

Add a Azure Table Storage input binding to a function. The input binding allows you to read table data as input to an Azure Function.

def read_table(table_name: str, connection: str, param_name: str, partition_key=None, row_key=None, filter=None):

Parameters:

  • str table_name : The name of the table.

  • str connection : The name of an app setting that contains the Storage connection string to use for this binding. The setting can be the name of an "AzureWebJobs" prefixed app setting or connection string name.

  • str param_name : The name of the variable that represents the table or entity in function code.

  • str partition_key : The partition key of the table entity to read.

  • str row_key : The row key of the table entity to read.

    • str filter : An OData filter expression for table input in JavaScript.

Azure Table output binding

Add a Azure Table Storage output binding to a function. The output binding allows you to write data to Azure Table.

def write_table(table_name: str, connection: str, param_name: str, partition_key=None, row_key=None):

Parameters:

  • str table_name : The name of the table.

  • str connection : The name of an app setting that contains the Storage connection string to use for this binding. The setting can be the name of an "AzureWebJobs" prefixed app setting or connection string name.

  • str param_name : The name of the variable that represents the table or entity in function code.

  • str partition_key : The partition key of the table entity to read.

  • str row_key : The row key of the table entity to read.