Programming Model : Binding Data
See original GitHub issueTrigger data and bindings will be communicated to the main() function via method arguments whose names are specified in function.json.
Inputs
There are two types of inputs: 1. trigger input and 2 . additional input. Although they are different in function.json, their usage is identical in the Python code.
# main.py
def main(trigger_input, binding_input):
# functions logic here
Outputs
Outputs can be expressed both in 1. return value and 2. output parameters. If there is only one output, we recommend using it as the return value. For multiple outputs, you have to use the function arguments.
To use the return value of your function as an output binding, label it using name : $return in function.json.
//function.json
{
"direction": "in",
"name": "my_input"
},
{
"direction": "out",
"name": "$return"
}
# main.py
def main(my_input):
# function logic here
return 'Value of the output binding.'
To produce multiple outputs, use the named function arguments of type azurefuncs.Out
. For example -
// function.json
{
"name": "trigger_input",
"direction": "in"
},
{
"name": "$return",
"direction": "out"
},
{
"name": "other_output",
"direction": "out",
}
# main.py
def main(trigger_input, other_output: azurefuncs.Out):
other_output = trigger_input
return 'Value of the output binding.'
Data Types
We will use function annotations (type hints) to define the data type of the binding arguments. The runtime will use this information to determine how to pass data into and return data from a function execution. For example -
# main.py
def main(my_input : str) -> bool:
print(f'Hello {my_input}')
return True
Alternately, you can define the dataType attribute in the function.json configuration.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:6
Top GitHub Comments
Everything described in this issue is now, except the question about
Out.get()
behaviour:Consider the following function:
So the current behaviour is to return
None
forOut
bindings that don’t have a value set (instead of raising an error). This is similar to how NodeJS binding is implemented and I think it’s OK for Python too.Closing this issue.