Using Modules

In this post we’ll learn how to define a function in a module, and then import and call it from a flow.

A full working example is available in the demo folder: (2.4 KB)

Sharing functionality between flows

Let’s say we have a recurring data source in our project that gives us comma separated property strings like this:


A property is either of the form name=value, or just name. When only the property name is present, it should be treated like a boolean flag, so enabled practically means enabled=true.

Let’s say we created a function to parse these strings such that we get results like this:

The rules are sufficiently non-trivial that we’d like to define the parsing function only once, and any flows that need it should be able to reference it.

Creating the module

To do that, we can create a new module and place our parse function in the variables section.

The module is ready to be used by any flows that need it.

Importing the module

In our data flow, we can import the variables section of the module and give it a name inside the flow. Here’ I called the imported section: utils

Our parsing function is now available anywhere in the flow as utils.parse_props. I’m using it in the calculator step to parse input strings:

Running the example flow we get the expected results:

1 Like