- Print
- DarkLight
- PDF
Some EchoStream Nodes allow you to provide custom Python functionality to process messages in those Nodes. For example, Processor and Cross Tenant Sending Nodes can take a processor function that allows you to customize the processing done by those Nodes. Providing custom Python code to accomplish this offers great flexibility, but for common or complex processing it can be advantageous to have reuable code that can be referenced instead.
This is where Functions come in. Functions are reuable processing code that can be referenced (and used as a basis for custom processing!) when you create or modify certain Nodes.
Functions are stored in your Tenant's Function Library. Any changes to a Function are immediately applied to all Nodes that use that Function.
Code
The actual Python code of the Function. Just like custom functions in your Nodes, all Python code in your Function must be contained within a single top-level def
declaration.
The signature of the Function's def
declaration is dependant on the Function's type.
Argument Message Type
All Bitmapper and Processor Functions have an Argument Message Type. This is the type of message that will be passed to the function for processing.
Return Message Type
Functions that return messages (i.e. - Processor Functions) will have a Return Message Type. This is the type of message that will be returned by the Functions after processing.
Requirements
Functions may require third-party Python packages to process the messages they are given. EchoStream allows Functions to specify these packages in the requirements
field, which is a list of packages required by the Function.
Note - in addition to the requirements listed directly for the Function, the Function will also inherit the requirements specified in any Message Type that it uses.
For example:
- A Function needs to query an external PostgreSQL database and add information returned to the message it is processing. In this case, the Function would add
psycopg2
to the list of its requirements to ensure that the PostgreSQL driver was avaiable at runtime. - A Function needs to convert JPEG images into PNG images during processing of
echo.file
messages. In this case, the Function lists thePillow
Python package as a requirement to ensure that the image conversion functionality provided byPillow
is available at runtime.
These requirements are pip
requirements specifiers and must be accessible using a standard pip install ...
call.
Requirements included in a Function will be included every time a Node uses that Function.
README
Functions include a README in Markdown format that explains the Function in a human-readable fashion