This guide shows how to link a simple function to Composo Cloud.

Under then hood, every app in Composo is a Python function that’s been linked to the Composo platform. Composo treats the arguments of your function as the Composo App’s inputs, and the return value of your function is the App’s output.

Install the Composo package

Install the latest version of the Composo package from PyPi

pip install --upgrade composo

Import the Composo package into Python

Install the latest version of the Composo package from PyPi

import composo as cp

Decorate your chosen function

@cp.Composo.link()
def adder(...

The decorator is responsible for managing the Live Connection with Composo Cloud. The Live Connection is established the first time the decorated function is invoked.

If left blank, upon initial connection the composo package will print a joining link and an API key.

For the full list of options that can be passed to cp.Composo, see the package API reference.

Annotate parameters

Parameters to be controlled by Composo and visible through Composo Cloud should be typed with the corresponding Composo type.

This let’s Composo know how to render the parameter in the platform, and also allows extra configuration to be specified.

Here’s a simple example demonstrating how to annotate function arguments

def adder(
	a: cp.IntParam
	b: cp.StrParam(description="a great argument to set")
	c: cp.FloatParam(min=0, max=2)
):

For the full list of supported argument types, see the package API reference.

And run

The Live Connection is established the first time the function is invoked.

The Composo package has two distinct runtime behaviours.

Production Mode (default)

Runs the Live Connection in a separate process. Designed to have minimal interference with the linked application.

This can be deployed with a production application with minimal (typically 0.002 - 0.05 milliseconds) additional latency per invocation.

Development Mode

Run the LiveConnection in the main thread, thereby blocking execution of the remaining program.

Particularly useful for scripts or apps where the triggering mechanism is handled externally e.g. cron, FaaS

If Python is not running, the Live Connection is not active. If your program exits before you’ve been able to run your tests in Composo, try running in development mode.

Full Example

import composo as cp

@cp.Composo.link()
def adder(a: cp.IntParam, b: cp.FloatParam, c: cp.StrParam):
	return a + b + float(c)

adder(1, 2.0, "3.0")

After running the file, a joining link and API key will be printed to the console. These can be used to complete the linking process in Composo Cloud.