Chapter 7. Developing OpenWhisk Actions in Python
In this chapter, you will learn how to write OpenWhisk actions using Python.
While knowledge of Python is a prerequisite to fully understand the examples in this chapter, the code should be comprehensible to most developers as Python is one of the easiest and most readable programming languages around. Still, I recommend that you check out the Python tutorial before reading this chapter and Chapter 9 if you haven’t worked with Python before.
Note
The source code for this chapter’s examples is available in the GitHub repository.
The Python Runtime
Let’s start by exploring the Python runtime. As you’ll see, it executes actions similar to the examples we saw earlier.
You develop your actions by creating a function, main, that will receive a dictionary as input and must also return a dictionary as output (you can specify a different function name if you want).
For example:
def main(args):name = args.get("name", "world")
greeting = "Hello " + name + "!" print(greeting)
return {"hello": greeting }
The entry point is a function with ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access