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.
LineCommand : Outbound command to a hardware signal line.
LineReading : Timestamped reading from a hardware signal line.
SignalBlockI32 : A block of 32-bit integer samples.
SignalBlockU16 : A block of 16-bit unsigned integer samples.
SignalBlockF32 : A block of 32-bit float samples.
An EDL dataset that holds data files for a modality.
Register an auxiliary data file (or scan pattern).
Returns the path where the data should be written (pathlib.Path).
Return the path for a data file with the given basename (pathlib.Path).
The file is not registered. Use a scan pattern to include it in the manifest.
An EDL group that can contain datasets and sub-groups.
A video frame.
Handle for a hardware input line. Use this to configure an input on the
downstream device; subsequent readings arrive as LineReading messages
on the consuming module's input port, matched by line_id.
Construct an input-line handle.
Parameters
- port: The
OutputPortcarryingLineCommandmessages. - line_id: Hardware line / channel / pin number.
- pullup:
Trueto enable the input pull-up resistor (default:False).
Emit the SET_MODE command that configures the line as an input.
Call this at the start of every run.
Returns
The
LineCommandthat was submitted.
Handle for a hardware output line (Firmata pin, DAQ channel, TTL line, ...).
Construction captures the port and line identity but emits no command. Call
send_mode() at the start of every run to configure the line on the
downstream device.
Construct an output-line handle.
Parameters
- port: The
OutputPortcarryingLineCommandmessages. - line_id: Hardware line / channel / pin number.
- analog:
Trueif this is an analog DAC output,Falsefor digital (default).
Emit a digital pulse on the line (digital lines only).
Parameters
- duration_msec: Pulse duration in microseconds (default: 2500).
Raises
- SyntalosPyError: If this is an analog line.
Returns
The
LineCommandthat was submitted.
Emit a digital pulse on the line (digital lines only).
Parameters
- duration_msec: Pulse duration in milliseconds (default: 50).
Raises
- SyntalosPyError: If this is an analog line.
Returns
The
LineCommandthat was submitted.
Emit the SET_MODE command that configures the line as an output.
Call this at the start of every run.
Returns
The
LineCommandthat was submitted.
Write an analog DAC value to the line (analog lines only).
Parameters
- value: DAC code (interpretation is device-specific).
Raises
- SyntalosPyError: If this is a digital line.
Returns
The
LineCommandthat was submitted.
Write a digital value to the line (digital lines only).
Parameters
- value:
True/1for HIGH,False/0for LOW.
Raises
- SyntalosPyError: If this is an analog line.
Returns
The
LineCommandthat was submitted.
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.
Command issued to a hardware signal line.
Type of operation requested on a hardware signal line.
Members:
UNKNOWN
SET_MODE : Configure a line's direction / mode (uses flags).
WRITE_DIGITAL : Set a digital line to a value (True/False).
WRITE_ANALOG : Set an analog line to a value.
WRITE_DIGITAL_PULSE : Pulse a digital line for duration.
WRITE_ANALOG_PULSE : Drive an analog line for duration.
DEVICE_SPECIFIC : Device-defined payload carried in extra.
Composable mode flags for LineCommandKind.SET_MODE.
Members:
NONE
IS_INPUT : Line is an input.
IS_OUTPUT : Line is an output.
PULL_UP : Input pull-up resistor enabled (inputs only).
Timestamped scalar reading from a hardware signal line.
Two-dimensional size value used in stream metadata.
A module output port.
Obtain an instance via get_output_port().
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.
Synchronizer for an external steady monotonic clock.
Obtain an instance via SyntalosLink.init_clock_synchronizer().
Process a master/secondary timestamp pair.
Returns the (possibly adjusted) master timestamp, in microseconds.
Set the number of calibration points required to compute the initial offset.
Auto-tune tolerance and required calibration points based on the expected DAQ frequency.
Set the bitset of TimeSyncStrategy values the synchronizer may apply.
Set the tolerance for offset deviations, in microseconds.
The current dynamic clock-correction offset, in microseconds.
Negative values indicate the secondary clock is running too slow, positive values indicate it is running too fast.
A block of timestamped 32-bit float signal data.
A block of timestamped 32-bit integer signal data.
A block of timestamped 16-bit unsigned integer signal data.
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.
Create a new dataset inside the given group with MUST_CREATE semantics.
Parameters
- group: Parent
EdlGroup. - name: Dataset name.
Returns
The new
EdlDataset.
Create the default dataset for this module under the assigned EDL root group.
Uses MUST_CREATE semantics: fails if a dataset with the same name already exists.
Must be called inside on_prepare.
Parameters
- preferred_name: Dataset name; defaults to the module's group name.
Returns
The new
EdlDataset.
Create (or open) a sub-group under the module's assigned EDL root group.
Parameters
- name: Group name.
Returns
The
EdlGroup.
Create a synchronizer for an external steady monotonic clock.
Must be called while the module is preparing or running (typically inside
on_prepare).
Parameters
- expected_frequency_hz: Optional expected acquisition frequency in Hz; if greater than zero it auto-tunes the calibration point count and tolerance.
- id: Optional synchronizer id; defaults to the module instance id.
Returns
A new
SecondaryClockSynchronizer.
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.
Register a callback invoked when Syntalos starts a run.
Type: Callable[[], None] | None.
Common base class for all non-exit exceptions.
Strategies a synchronizer may apply to keep a secondary timeline aligned with the master clock.
Values are bit flags and may be combined with |.
Members:
NONE : Do nothing.
SHIFT_TIMESTAMPS_FWD : Move timestamps forward to match the master clock.
SHIFT_TIMESTAMPS_BWD : Move timestamps backward to match the master clock.
ADJUST_CLOCK : Adjust the secondary clock to match the master clock without changing timestamps.
WRITE_TSYNCFILE : Write a time-sync file for offline offset correction in postprocessing.
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.
Parameters
- rename_process: Rename the current process to match the module identifier.:return: 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 LineCommand for the given line.
Parameters
- kind: The
LineCommandKindto execute. - line_id: Hardware line / channel / pin number.
- value: Optional numeric value (digital: 0/1; analog: DAC code).
Returns
A new
LineCommandinstance.
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.