Apache OpenWhisk Composer Python provides a high-level programming model in Python for composing serverless functions

Clone this repo:


  1. 948d299 Feature #19: a user can now create a new composition with fine-grained limits (#22) by Pedro Escaleira · 8 months ago master
  2. 09d480d Fixed issue #18: the conductor's synthesize function is now able to process the pydeploy's annotations (#21) by Pedro Escaleira · 8 months ago
  3. 12b2fa9 Fixed issue #17: now, both annotation and annotation-file flags work properly on pydeploy (#20) by Pedro Escaleira · 8 months ago
  4. cc0824a remove travis from required checks for merging PRs (#16) by David Grove · 1 year, 6 months ago
  5. 471c2a5 configure more github properties via asf.yaml (#14) by David Grove · 3 years, 3 months ago


Build Status License JoinSlack

This repository provides a Python library for Composer. For convenience, the Composer documentation is repeated below using Python bindings instead of JavaScript.

Composer is a new programming model for composing cloud functions built on Apache OpenWhisk. With Composer, developers can build even more serverless applications including using it for IoT, with workflow orchestration, conversation services, and devops automation, to name a few examples.

This repository includes:


You need python3.6 installed on your system.

From github

$ git clone https://github.com/apache/openwhisk-composer-python.git
$ cd composer-python
$ pip3 install -e .
$ pycompose -h
usage: pycompose composition.py command [flags]
$ pydeploy -h
usage: pydeploy composition composition.json [flags]

From PyPi (Not available yet)

Composer will eventually be distributed on PyPi. Once it is available, to install this package, use pip:

$ pip3 install openwhisk-composer

Shell embeds the Composer package, so there is no need to install Composer for Python explicitly when using Shell.

Defining a composition

A composition is typically defined by means of a Python expression as illustrated in samples/demo.py:

import composer

def main():
    return composer.when(
        composer.action('authenticate',  { 'action': lambda args: { 'value': args['password'] == 'abc123' } }),
        composer.action('success', { 'action': lambda args: { 'message': 'success' } }),
        composer.action('failure', { 'action': lambda args: { 'message': 'failure' } }))

Compositions compose actions using combinator methods. These methods implement the typical control-flow constructs of a sequential imperative programming language. This example composition composes three actions named authenticate, success, and failure using the composer.when combinator, which implements the usual conditional construct. It takes three actions (or compositions) as parameters. It invokes the first one and, depending on the result of this invocation, invokes either the second or third action.

Deploying a composition

One way to deploy a composition is to use the pycompose and pydeploy commands:

pycompose demo.py > demo.json
pydeploy demo demo.json -w
ok: created /_/authenticate,/_/success,/_/failure,/_/demo

The pycompose command compiles the composition code to a portable JSON format. The pydeploy command deploys the JSON-encoded composition creating an action with the given name. It also deploys the composed actions if definitions are provided for them. The -w option authorizes the deploy command to overwrite existing definitions.

Running a composition

The demo composition may be invoked like any action, for instance using the OpenWhisk CLI:

wsk action invoke demo -p password passw0rd
ok: invoked /_/demo with id 09ca3c7f8b68489c8a3c7f8b68b89cdc

The result of this invocation is the result of the last action in the composition, in this case the failure action since the password in incorrect:

wsk activation result 09ca3c7f8b68489c8a3c7f8b68b89cdc
    "message": "failure"

Execution traces

This invocation creates a trace, i.e., a series of activation records:

wsk activation list

The entry with the earliest start time (09ca3c7f8b68489c8a3c7f8b68b89cdc) summarizes the invocation of the composition while other entries record later activations caused by the composition invocation. There is one entry for each invocation of a composed action (5dceeccbdc7a4caf8eeccbdc7a9caf18 and 7efb6b7354c3472cbb6b7354c3272c98). The remaining entries record the beginning and end of the composition as well as the transitions between the composed actions.

Compositions are implemented by means of OpenWhisk conductor actions. The documentation of conductor actions explains execution traces in greater details.