Python Module API
Syntalos provides a Python API to easily build new modules. Python modules do not
run within the Syntalos process, and instead communicate with the main application
via an interface provided by the syntalos_mlink Python module.
This API can be used from either the Python Script module, or by
standalone modules that are written in Python entirely.
The Python interface is documented below.
syntalos_mlink
Syntalos Python Module Interface
A control command for a module.
The type of a control command sent to controllable modules.
Members:
UNKNOWN
START : Start an operation.
PAUSE : Pause an operation; can be resumed with START.
STOP : Stop an operation.
STEP : Advance operation by one step.
CUSTOM : Custom command.
Identifies the data type of a port / stream.
Members:
ControlCommand : Module control command.
TableRow : A row of tabular data.
Frame : A video frame.
FirmataControl : Firmata device control message.
FirmataData : Data received from a Firmata device.
IntSignalBlock : A block of integer signal samples.
FloatSignalBlock : A block of float signal samples.
Type of change to be made on a Firmata interface.
Members:
UNKNOWN
NEW_DIG_PIN : Register a new digital pin.
NEW_ANA_PIN : Register a new analog pin.
IO_MODE : Change a pin's I/O mode.
WRITE_ANALOG : Write an analog value to a pin.
WRITE_DIGITAL : Write a digital value to a pin.
WRITE_DIGITAL_PULSE : Emit a digital pulse on a pin.
SYSEX : Send a raw SysEx message.
Control command for a Firmata device.
Data received from a Firmata device.
A block of timestamped float signal data.
A video frame.
A module input port.
Obtain an instance via get_input_port().
Limit the number of items delivered to on_data per second.
Parameters
- items_per_sec: Maximum items per second;
0disables throttling.
Read-only dict[str, object] of metadata provided by the upstream module for this port.
Values are native Python types: int, float, str, bool, None,
MetaSize, or list / dict for nested structures.
Callback invoked with each incoming data item.
Assign a callable that accepts a single argument of the port's data type
(e.g. Frame, TableRow). Set to None to remove the callback.
Type: Callable[[object], None] | None.
A block of timestamped integer signal data.
Two-dimensional size value used in stream metadata.
A module output port.
Obtain an instance via get_output_port().
Register a named digital pin on the connected Firmata device and submit the command immediately.
The pin can subsequently be referenced by name in firmata_submit_digital_value()
and firmata_submit_digital_pulse().
Parameters
- pin_id: Numeric pin identifier on the device.
- name: Human-readable name to register for this pin.
- is_output:
Trueto configure the pin as output,Falsefor input. - is_pullup:
Trueto enable the internal pull-up resistor (default:False).
Returns
The
FirmataControlcommand that was submitted.
Emit a digital pulse on a previously registered pin.
Parameters
- name: Registered pin name.
- duration_msec: Pulse duration in milliseconds (default: 50).
Returns
The
FirmataControlcommand that was submitted.
Write a digital value to a previously registered pin.
Parameters
- name: Registered pin name.
- value:
True/1for HIGH,False/0for LOW.
Returns
The
FirmataControlcommand that was submitted.
Set a metadata entry for this port.
Metadata must be set before the run starts (i.e. in prepare()); it is immutable once
acquisition begins.
Parameters
- key: Metadata key string.
- value: Metadata value. Accepted types:
int,float,str,MetaSize, orlistofint/strvalues.
Raises
- SyntalosPyError: If the value type is not supported.
Set a 2-D size metadata entry for this port (e.g. 'size' for video streams).
Parameters
- key: Metadata key string.
- value: Either a
MetaSizeobject or a sequence of exactly two integers[width, height].
Raises
- SyntalosPyError: If
valuedoes not have exactly two elements.
Send a data item to all modules connected to this port.
Parameters
- data: Data item matching this port's type (e.g.
Frame,TableRow).
Raises
- SyntalosPyError: If the item type does not match the port's declared data type.
Manages the connection to Syntalos.
Single-shot data poll for use inside a custom event loop.
Parameters
- timeout_usec: Maximum time to block in µs;
-1waits indefinitely.
Signal initialization complete and run the module event loop.
Signals IDLE to Syntalos then blocks until a shutdown is requested.
Parameters
- event_fn: Optional zero-argument callable, invoked regularly to pump an external event loop.
Declare a new input port for this module.
Must be called at module level so that Syntalos can discover the port topology and restore project connections before the first run is prepared.
Parameters
- id: Unique port identifier used in
get_input_port(). - title: Human-readable port label shown in the flow-graph editor.
- data_type:
DataTypevalue, e.g.DataType.Frame,DataType.TableRow.
Returns
An
InputPorthandle.
Declare a new output port for this module.
Must be called at module level (top-level script code, not inside a function) so that Syntalos can discover the port topology and restore project connections before the first run is prepared.
Parameters
- id: Unique port identifier used in
get_output_port(). - title: Human-readable port label shown in the flow-graph editor.
- data_type:
DataTypevalue, e.g.DataType.Frame,DataType.TableRow.
Returns
An
OutputPorthandle.
Signal IDLE (initialization complete) without entering the built-in event loop.
Call this before starting a custom loop with await_data().
Whether start() is run in parallel with other modules for this module.
On startup, Syntalos can send START to all external modules in parallel,not waiting for them to finish individual START actions. This is the async-start method, and it results in much better aligned start times of modules.However, some modules may need to modify stream metadata in START and must ensure it is receivedbefore their streams are started. Those modules may want to disable async-start for themselves, so they run exclusively and the enginewaits for them to complete START actions.
Check whether the experiment is still active.
Returns
Truewhile the run is in progress,Falseonce a stop has been requested.
Register a callback invoked when Syntalos loads settings for this module.
The callback receives the loaded settings payload first (bytes / bytearray), followed by
the base project directory as pathlib.Path.
The callback must return True to signal that the settings were loaded successfully, or False / use raise_error to signal a loading failure.
If not registered, incoming settings are ignored.
Type: Callable[[bytes | bytearray, pathlib.Path], bool] | None.
Register a callback invoked when Syntalos prepares a new run.
The callback must return True to signal that preparation succeeded,
or False / raise an exception to abort.
If not registered the module automatically signals readiness.
Type: Callable[[], bool] | None.
Register a callback invoked when Syntalos saves settings for this module.
The callback receives the base project directory as a pathlib.Path and must return a
bytes-like payload (bytes or bytearray). If not registered, no module settings are saved.
Type: Callable[[pathlib.Path], bytes | bytearray] | None.
Register a callback invoked when the user opens the module display window.
Type: Callable[[], None] | None.
Register a callback invoked when the user opens the module settings dialog.
Type: Callable[[], None] | None.
Common base class for all non-exit exceptions.
Wait for incoming data and dispatch it to registered on_data callbacks.
Also services the IPC channel to the Syntalos process. Call this regularly
inside a run() loop to keep the module responsive.
Parameters
- timeout_usec: Maximum time to block in microseconds. Pass
-1(default) to wait until the module is no longer inRUNNINGstate.
Retrieve a reference to an input port by its ID.
Parameters
- id: The port ID (assigned via
SyntalosLink.register_input_port()or via the PyScript GUI editor).
Returns
An
InputPorthandle, orNoneif no port with that ID exists.
Retrieve a reference to an output port by its ID.
Parameters
- id: The port ID (assigned via
SyntalosLink.register_output_port()or via the PyScript GUI editor).
Returns
An
OutputPorthandle, orNoneif no port with that ID exists.
Initialize a connection with Syntalos.
This function must be called only once at program startup, before invoking any other methods on this module.
Returns
The active
SyntalosLinkregistry object.
Check whether the experiment is still active.
Returns
Truewhile the run is in progress,Falseonce a stop has been requested.
Create a FirmataControl command identified by numeric pin ID only.
Parameters
- kind: The
FirmataCommandKindto execute. - pin_id: Numeric pin identifier.
Returns
A new
FirmataControlinstance.
Create a FirmataControl command identified by both numeric ID and name.
Parameters
- kind: The
FirmataCommandKindto execute. - pin_id: Numeric pin identifier.
- name: Registered pin name.
Returns
A new
FirmataControlinstance.
Create a FirmataControl command identified by a registered pin name.
The pin must have been previously registered with OutputPort.firmata_register_digital_pin().
Parameters
- kind: The
FirmataCommandKindto execute. - name: Registered pin name.
Returns
A new
FirmataControlinstance.
Print a line of text to stdout.
Parameters
- text: The text to print.
Raise a module error, immediately stopping the current run.
Parameters
- message: Human-readable error description.
Schedule a callable to be invoked after a delay.
The call is executed on the module's event loop, so it is safe to interact with ports and other module state from the callback.
Signature: schedule_delayed_call(delay_msec: int, callable_fn: Callable[[], None]) -> None.
Parameters
- delay_msec: Delay before the call is made, in milliseconds. Must be >= 0.
- callable_fn: Zero-argument callable to invoke.
Raises
- SyntalosPyError: If
delay_msecis negative.
Return the time elapsed since the experiment started.
Returns
Elapsed time in milliseconds.
Return the time elapsed since the experiment started.
Returns
Elapsed time in microseconds.
Sleep for approximately the given number of milliseconds.
Unlike a plain time.sleep(), this keeps the communication channel to Syntalos
alive so that control messages (e.g. stop requests) are still handled.
Parameters
- msec: Duration to wait in milliseconds.
Sleep for approximately the given number of seconds.
Unlike a plain time.sleep(), this keeps the communication channel to Syntalos
alive so that control messages (e.g. stop requests) are still handled.
Parameters
- sec: Duration to wait in seconds.