question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Programming Model : Binding Data

See original GitHub issue

Trigger 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
1st1commented, Mar 1, 2018

Everything described in this issue is now, except the question about Out.get() behaviour:

Consider the following function:

import azure.functions as azf


def main(request: azf.HttpRequest, response: azf.Out[azf.HttpResponse):
    response.get() # will return None  (!!!)

    response = azf.HttpResponse(status_code=301)
    response.set(response)

    response.get() # will return "azf.HttpResponse(status_code=301)"

So the current behaviour is to return None for Out 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.

0reactions
1st1commented, Mar 1, 2018

Closing this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is Data Binding? - Definition from WhatIs.com - TechTarget
Data binding is the process that couples two data sources together and synchronizes them. With data binding, a change to an element in...
Read more >
Guide to ASP.NET MVC Model Binding - Simplilearn
The model binding applies to transforming the HTTP request data in the query's form string and form collection of the action method parameters....
Read more >
Retrieving and displaying data with model binding and web ...
Sorting, paging, and filtering data with model binding and web forms. This tutorial series demonstrates some basic aspects of using model ...
Read more >
14.4. Model-Binding — Java Web Development documentation
This is the essence of model binding. The model instance is created on form submission. With only two fields needed to create an...
Read more >
How Model Binding Works in ASP.NET MVC with Example
1. It is much cleaner code and there is no fancy coding. · 2. No type casting needed. · 3. No need to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found