Common Bridge Components
mosaicolabs.bridges.base_schema_metadata ¶
BaseSchemaMetadata ¶
Encapsulates Mosaico's reserved topic-metadata namespace in a single place.
Every topic ingested by the MCAP or ROS bridge carries specific bookkeeping
channel_name,channel_encoding,schema_name,schema_encoding, rawschema_deffor MCAPmsgtype, rawmsgdef, extractedenumsfor ROS
plus bridge-internal fields (e.g. the source mcap file) under one reserved key, so that:
- The literal
KEYstring exists in exactly one place, instead of being duplicated across adapters, loaders, and the injector. - Callers build up this namespace incrementally via
updatewithout ever touching the wrapping dict shape by hand.
KEY
class-attribute
¶
The reserved metadata key. It should be overridden by each BaseSchemaMetadata specification.
REQUIRED_KEYS
class-attribute
¶
The keys that need to be present in order to create the schema metadata. Empty by default
update ¶
Merges additional fields into this block, in place. Returns self for chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**fields
|
Any
|
Additional fields to merge. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
BaseSchemaMetadata |
BaseSchemaMetadata
|
The updated metadata instance. |
to_dict ¶
Wraps the current fields under the reserved key.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary containing the |
merge_into ¶
Merges this block into an existing metadata dict's KEY namespace, creating it
if absent. Mutates and returns metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
dict
|
The existing metadata dict to merge into. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The updated metadata dict with the |
extract
classmethod
¶
Reads the KEY block out of a metadata dict or {} if absent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
Optional[dict]
|
A metadata dict, typically |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The extracted |
from_dict
classmethod
¶
Creates a BaseSchemaMetadata from a plain metadata dict, e.g. the return value of
ROSAdapterBase.schema_metadata(). Any keys outside the KEY namespace are ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
Optional[dict]
|
A metadata dict, typically |
required |
Returns:
| Name | Type | Description |
|---|---|---|
BaseSchemaMetadata |
BaseSchemaMetadata
|
A new instance seeded with the extracted |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any of |
TypeError
|
If any of |
mosaicolabs.bridges.base_sequence_extractor ¶
SequenceExtractor: streams a Mosaico sequence back out and writes it to a file on disk.
Provides SequenceExtractor
and the ExtractorConfig
dataclass, which together own the target-agnostic half of the extraction pipeline:
- Prepare (and optionally clear) the output location.
- Connect to the Mosaico server.
- Stream every message in the requested sequence (optionally filtered by topic or
time window) through a
MosaicoLoader. - Hand each message to the specialization, which encodes it and writes it out.
Everything that depends on the target format (which loader to open, which writer to
open, and how a single message is encoded and written) lives in a subclass. See
ROSSequenceExtractor and
MCAPSequenceExtractor.
The module also provides the command-line arguments shared by the extractors' entry points.
ExtractorConfig
dataclass
¶
ExtractorConfig(
saving_path,
sequence_name,
host="localhost",
port=6726,
topics=None,
log_level="INFO",
mosaico_api_key=None,
tls_cert_path=None,
enable_tls=False,
start_timestamp_ns=None,
end_timestamp_ns=None,
overwrite=False,
dry_run=False,
)
Shared configuration for every
SequenceExtractor.
Collects the parameters that do not depend on the output format: how to reach the Mosaico server, which sequence to extract, how to filter it by topic and time window, and where to write the result.
Attributes:
| Name | Type | Description |
|---|---|---|
saving_path |
Path
|
The path where to save the final file. |
sequence_name |
str
|
The name of the sequence to extract. |
host |
str
|
The hostname of the Mosaico server. Defaults to |
port |
int
|
The port of the Mosaico server. Defaults to |
topics |
Optional[list[str]]
|
List of topic patterns (shell-style globs, |
log_level |
str
|
The log level. Defaults to |
mosaico_api_key |
Optional[str]
|
The API key for authentication on the Mosaico
server; it must have (at least) the |
tls_cert_path |
Optional[str]
|
Path to the TLS certificate file for a secure connection to the Mosaico server. Defaults to None. |
enable_tls |
bool
|
Enable standard one-way TLS (server authenticated only).
Ignored if |
start_timestamp_ns |
Optional[int]
|
Inclusive lower-bound timestamp (in nanoseconds) from which to start extracting data. Defaults to None. |
end_timestamp_ns |
Optional[int]
|
Exclusive upper-bound timestamp (in nanoseconds) at which to stop extracting data. Defaults to None. |
overwrite |
bool
|
If True, delete and recreate the output path if it already exists. Defaults to False. |
dry_run |
bool
|
If True, report which topics would be extracted or rejected and whether the output path already exists, without writing or deleting any file. Defaults to False. |
topics
class-attribute
instance-attribute
¶
List of topic patterns used to filter available topics.
Supports shell-style glob patterns (e.g., "/cam/", "camera_info"). Patterns starting with '!' are treated as exclusions (e.g., "!/cam/debug*").
Pattern order matters: - Each non-'!' pattern adds matching topics to the selection. - Each '!' pattern removes matching topics from the selection. - Later patterns override earlier ones. - If no inclusion pattern is provided, selection starts from ALL topics, and only exclusion patterns reduce the set.
If None, all topics are loaded.
mosaico_api_key
class-attribute
instance-attribute
¶
The API key for authentication on the mosaico server. Defaults to None.
If provided it must have (at least) the read permission.
tls_cert_path
class-attribute
instance-attribute
¶
Path to the TLS certificate file for secure connection on the mosaico server. Defaults to None. If tls_cert_path=None and enable_tls=True, a standard one-way TLS (server authenticated only) connection is established
enable_tls
class-attribute
instance-attribute
¶
Enable the TLS standard one-way TLS (server authenticated only) communication protocol. Defaults to False. If tls_cert_path is provided (not None), this flag does not have any effect.
start_timestamp_ns
class-attribute
instance-attribute
¶
Inclusive timestamp upper-bound (in nanoseconds) from where to start extracting data of specified sequence
end_timestamp_ns
class-attribute
instance-attribute
¶
Exclusive timestamp lower-bound (in nanoseconds) to finish extracting data of specified sequence
overwrite
class-attribute
instance-attribute
¶
If True, delete and recreate the output path if it already exists. Defaults to False.
dry_run
class-attribute
instance-attribute
¶
If True, connects to the Mosaico server and reports which topics would be extracted
(and with which adapter/native message type), which topics would be rejected (and why),
and whether the output path already exists, without writing any file and without
deleting an existing output path even if overwrite=True. Default: False.
SequenceExtractor ¶
Bases: ABC
Orchestrates the extraction of a Mosaico sequence into a file on disk.
This is the target-agnostic half of the extraction pipeline: preparing the output
location and enforcing the overwrite policy, connecting to the Mosaico server, driving
the loader that streams the sequence, reporting live progress and, in dry-run mode,
printing what would be extracted. Everything that depends on the output format lives
in a subclass; see
ROSSequenceExtractor and
MCAPSequenceExtractor.
A subclass supplies exactly three things:
_open_mosaicoloader: theMosaicoLoaderspecialization that adapts the sequence into the target format._open_writer: the writer that turns encoded messages into a file._process_message: the per-message encode-and-write step.
run, _dry_run_report, _prepare_output_path and _handle_encoding_error are
inherited unchanged.
Attributes:
| Name | Type | Description |
|---|---|---|
cfg |
ExtractorConfig
|
The configuration this extractor was built with. |
console |
Console
|
The |
ignored_topics |
set[str]
|
Topics dropped mid-run after a failure. Specializations
add to it from |
Initializes the shared state, console and SDK logging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
ExtractorConfig
|
A bridge-specific configuration subclass. |
required |
run ¶
Executes the full extraction pipeline.
Steps:
- If
cfg.dry_runisTrue, delegates to_dry_run_reportand returns without writing a file or touching the output path. - Calls
_prepare_output_pathto validate / clear the output location. - Opens a
MosaicoClientconnection. - Opens the loader via
_open_mosaicoloaderand the writer via_open_writer, both as context managers, so both are released even on failure. - For each
(topic, message)pair streamed by the loader, delegates to_process_message, which encodes and writes it.
Progress is displayed in real-time via a rich live progress bar. A
KeyboardInterrupt exits cleanly with a warning log; any other exception
propagates to the caller.
Raises:
| Type | Description |
|---|---|
FileExistsError
|
If the output path exists and |
ValueError
|
If the configured sequence does not exist on the server (surfaced by the loader). |
mosaicolabs.bridges.bridge_adapter_base ¶
BridgeAdapterBase ¶
Bases: ABC, Generic[T, NativeMsgT]
Common interface implemented by every bridge adapter (e.g. :class:ROSAdapterBase,
:class:MCAPAdapterBase).
An adapter is the semantic core of a bridge: it knows how to translate one native
message format (NativeMsgT, e.g. a ROS message or an MCAP record) to and from a
strongly-typed Mosaico ontology object (T).
to_native
abstractmethod
classmethod
¶
Converts a Mosaico message or ontology object into the adapter's native message type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mosaico_data
|
Union[Message, T]
|
A |
required |
**kwargs
|
Any
|
Bridge-specific extra arguments forwarded to the underlying conversion. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
NativeMsgT |
NativeMsgT
|
The native message obtained from |
translate
abstractmethod
classmethod
¶
Translates a native message instance into a Mosaico Message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
The source native message yielded by the bridge's loader. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
A Mosaico Message object containing the instantiated ontology data. |
Raises:
| Type | Description |
|---|---|
Exception
|
If translation fails due to missing fields, type mismatches, or other errors. |
unpack_mosaico_msg
classmethod
¶
Extracts the typed Mosaico payload and its Header (if present) from a wrapped or bare message.
Handles two input cases:
Messagewrapper: the typed data is extracted viaget_data().- Raw ontology instance: returned as-is.
In both cases the Header is extracted from the ontology (if supported), otherwise a
default Header (empty frame_id and zero Time) is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mosaico_msg
|
Union[Message, T]
|
Either a |
required |
Returns:
| Type | Description |
|---|---|
T
|
tuple[T, Header]: A |
Header
|
header is the corresponding |
tuple[T, Header]
|
zero |
Raises:
| Type | Description |
|---|---|
TypeError
|
If mosaico_msg is neither a |
mosaicolabs.bridges.loader_base ¶
TopicResolution
dataclass
¶
Bases: Generic[AdapterT]
The outcome of resolving a single topic: either an adapter to translate it with, or the reason it was rejected.
Build these with accepted / rejected rather than by hand — the
constructor enforces that exactly the accepted case carries an adapter.
Attributes:
| Name | Type | Description |
|---|---|---|
status |
TopicStatus
|
|
adapter |
Optional[Type[AdapterT]]
|
The resolved adapter class. Set if and only
if |
native_msg_type |
Optional[str]
|
The source-format message type the topic
originally came from (e.g. |
detail |
str
|
Human-readable context for a rejection, used for logging. |
is_accepted
property
¶
Whether this topic was accepted and therefore carries an adapter.
accepted
classmethod
¶
Builds the accepted outcome.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Type[AdapterT]
|
The adapter class resolved for this topic. |
required |
native_msg_type
|
str
|
The topic's original source-format message type. |
required |
Returns:
| Type | Description |
|---|---|
TopicResolution[AdapterT]
|
TopicResolution[AdapterT]: An |
rejected
classmethod
¶
Builds a rejected outcome.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
|
TopicStatus
|
Why the topic was rejected. Must not be |
required |
detail
|
str
|
Optional human-readable context, surfaced in the loader's log line. |
''
|
Returns:
| Type | Description |
|---|---|
TopicResolution[AdapterT]
|
TopicResolution[AdapterT]: A rejection carrying no adapter. |
BaseLoader ¶
Bases: ABC, Generic[AdapterT]
Shared topic classification and adapter-resolution logic for
- ROSLoader (bag file source)
- MCAPLoader (mcap file source)
- MosaicoLoader (Mosaico sequence source).
All loaders classify every topic of their underlying data source as either
accepted (adapter resolved, passes the user's topics filter) or rejected,
the latter carrying a TopicStatus saying why — excluded by the user's
filter, no adapter resolvable, or a source-specific reason such as
TopicStatus.NOT_IN_TYPESTORE or TopicStatus.UNAVAILABLE_SCHEMA. This base
class implements the properties that only need to read that bookkeeping, so each
subclass only has to populate it via its own _ensure_resolved() (which performs the
actual, source-specific resolution: opening the bag file, or querying the Mosaico
sequence).
Subclasses are expected to set, during _ensure_resolved():
_resolved_topics: all topic names in the source (dict or list; only the keys/elements are read by this base class)._accepted_topics: topic names that passed filtering and adapter resolution._topic_cached_adapters:Dict[str, Type[AdapterT]]mapping accepted topic names to their resolved adapter.
and record every rejection through _reject, which is the single place
rejection reasons live — there are no per-reason buckets to keep in sync.
topics
property
¶
Retrieves the list of accepted topic names that will be processed.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of topic names currently matched and scheduled for loading. |
resolved_topics
property
¶
Retrieves the list of all the canonical topic names in the underlying source. This property does not account for topics filtered out or not-adapted: it returns everything.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of all topic names contained within the source. |
unresolved_adapter_topics
property
¶
Retrieves the list of topic names that are skipped due to unavailable Mosaico adapter.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of topics with unresolved adapter to translate them into/from Mosaico Ontology. |
filtered_topics
property
¶
Retrieves the list of topic names that are skipped due to the user filter.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: The list of topics filtered by the user. Empty if no filter is provided. |
rejected_topics
property
¶
Retrieves every rejected topic together with the reason it was rejected.
Returns:
| Type | Description |
|---|---|
List[Tuple[str, TopicStatus]]
|
List[Tuple[str, TopicStatus]]: |
resolve_adapter ¶
Returns the resolved adapter for an accepted topic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
topic_name
|
str
|
The topic name whose adapter should be resolved.
Must be one of the accepted topics produced by |
required |
Returns:
| Type | Description |
|---|---|
Optional[type[AdapterT]]
|
Optional[Type[AdapterT]]: The resolved adapter type, or |
MosaicoLoader ¶
MosaicoLoader(
m_client,
sequence_name,
topics=None,
start_timestamp_ns=None,
end_timestamp_ns=None,
)
Bases: BaseLoader[AdapterT], Generic[AdapterT]
Streams messages back out of a Mosaico sequence, adapting each one into a native format on the way.
This is the source-agnostic half of the extraction pipeline: connecting to the
server, resolving the sequence and its topic filter, clipping the time window to the
sequence bounds, deciding which topics can be adapted, and exposing a
SequenceDataStreamer for iteration.
Everything that depends on the target format lives in a subclass — see
MosaicoToROSLoader and MosaicoToMCAPLoader.
A subclass supplies exactly two things:
SCHEMA_METADATA— the reserved metadata namespace its bridge writes at ingestion time (_ros_,_mcap_, ...), used to recover per-topic bookkeeping._resolve_topic— given a topic, the adapter and native message type to use, or the reason the topic is rejected.
Conforms to the LoaderUIAPI protocol, making it usable with
ProgressManager for live progress reporting.
Initializes the loader against a Mosaico sequence.
Nothing is fetched here — the sequence is resolved lazily on first access to any
property or on iteration (see _resolve_sequence).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m_client
|
MosaicoClient
|
An open
|
required |
sequence_name
|
str
|
Name of the Mosaico sequence to load. |
required |
topics
|
Optional[List[str]]
|
Optional topic-name filter patterns (glob-style,
|
None
|
start_timestamp_ns
|
Optional[int]
|
Inclusive lower bound for the time window (nanoseconds). Clipped to the sequence minimum if out of range. |
None
|
end_timestamp_ns
|
Optional[int]
|
Exclusive upper bound for the time window (nanoseconds). Clipped to
|
None
|
SCHEMA_METADATA
class-attribute
¶
The reserved topic-metadata namespace this loader's bridge writes (e.g.
RosSchemaMetadata for _ros_). Every
subclass must set it; the base class cannot, since BaseSchemaMetadata has an empty
KEY and would silently extract nothing.
duration
property
¶
Returns the duration of the sequence in nanoseconds.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The duration of the sequence in nanoseconds. Returns 0 if sequence is not valid |
msg_types
property
¶
Returns the Mosaico ontology type tags for each accepted topic.
Entries appear in the same order as topics. A None entry
indicates that the topic handler could not be found.
Triggers lazy initialization on first access.
Returns:
| Type | Description |
|---|---|
List[str | None]
|
List[str | None]: Ontology tag strings (e.g. |
topics
property
¶
Retrieves the list of accepted topic names that will be processed.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of topic names currently matched and scheduled for loading. |
resolved_topics
property
¶
Retrieves the list of all the canonical topic names in the underlying source. This property does not account for topics filtered out or not-adapted: it returns everything.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of all topic names contained within the source. |
unresolved_adapter_topics
property
¶
Retrieves the list of topic names that are skipped due to unavailable Mosaico adapter.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of topics with unresolved adapter to translate them into/from Mosaico Ontology. |
filtered_topics
property
¶
Retrieves the list of topic names that are skipped due to the user filter.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: The list of topics filtered by the user. Empty if no filter is provided. |
rejected_topics
property
¶
Retrieves every rejected topic together with the reason it was rejected.
Returns:
| Type | Description |
|---|---|
List[Tuple[str, TopicStatus]]
|
List[Tuple[str, TopicStatus]]: |
msg_count ¶
Returns the total number of messages for the given topic, or for all accepted topics combined.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
topic
|
Optional[str]
|
If provided, count messages for that specific topic only.
If |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The total message count. |
resolve_native_msg_type ¶
Returns the native message type a topic was originally ingested as.
When a bag or mcap file is ingested into Mosaico, the source message type
(e.g. sensor_msgs/msg/Imu) is preserved in the topic's user metadata under
this bridge's reserved namespace. Recovering it lets the extraction pipeline
write the topic back out under its original type instead of falling back to
whatever type the adapter defaults to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
topic_name
|
str
|
The topic whose original message type should be resolved.
Must be one of the accepted topics produced by |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Optional[str]: The message type string (e.g. |
Optional[str]
|
or |
resolve_metadata ¶
Returns the metadata required for the topic reconstruction to the native message.
When a bag or mcap file is ingested into Mosaico, the source message metadata (e.g. message definition, original topic name, ...) are saved in the topic's user metadata under this bridge's reserved namespace. Recovering it lets the extraction pipeline write the topic back out under its original form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
topic_name
|
str
|
The topic whose reconstruction metadata should be resolved.
Must be one of the accepted topics produced by |
required |
Returns:
| Type | Description |
|---|---|
Optional[BaseSchemaMetadata]
|
Optional[BaseSchemaMetadata]: All the message metadata required for the
reconstruction, or |
resolve_adapter ¶
Returns the resolved adapter for an accepted topic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
topic_name
|
str
|
The topic name whose adapter should be resolved.
Must be one of the accepted topics produced by |
required |
Returns:
| Type | Description |
|---|---|
Optional[type[AdapterT]]
|
Optional[Type[AdapterT]]: The resolved adapter type, or |
mosaicolabs.bridges.topic_status ¶
TopicStatus ¶
Bases: Enum
Defines the possible topic status (ACCEPTED/REJECTED) for all Loaders.
Rejection statuses are reported by the loaders' rejected_topics property:
- All loaders (
ROSLoader,MosaicoLoader,MCAPLoader, viaBaseLoader):FILTERED,UNRESOLVED_ADAPTER. MosaicoLoaderonly (MosaicoToROSLoader,MosaicoToMCAPLoader):MALFORMED_METADATA, plusNOT_IN_TYPESTOREforMosaicoToROSLoader.MCAPLoaderonly:UNRESOLVED_DECODER,UNAVAILABLE_SCHEMA.
ACCEPTED is never reported as a rejection reason.
Attributes:
| Name | Type | Description |
|---|---|---|
ACCEPTED |
Enum specifying the Topic has been accepted. |
|
FILTERED |
Enum specifying the Topic has been rejected since user provided a filter that excludes the topic. |
|
UNRESOLVED_ADAPTER |
Enum specifying the Topic has been rejected since it has no Mosaico adapter. |
|
NOT_IN_TYPESTORE |
Enum specifying the Topic has been rejected since it is not present in ROS typestore. |
|
MALFORMED_METADATA |
Enum specifying the Topic has been rejected since its bridge metadata ( |
|
UNRESOLVED_DECODER |
Enum specifying the Channel has been rejected since its encoding does not have an implemented decoder. |
|
UNAVAILABLE_SCHEMA |
Enum specifying the Channel has been rejected since it does not contain any schema information. |
ACCEPTED
class-attribute
instance-attribute
¶
Status indicating an accepted Topic
FILTERED
class-attribute
instance-attribute
¶
Status indicating topic has been rejected by user specified filter
UNRESOLVED_ADAPTER
class-attribute
instance-attribute
¶
Status indicating the Topic has been rejected since no Mosaico adapter could be resolved
NOT_IN_TYPESTORE
class-attribute
instance-attribute
¶
Status indicating the Topic has been rejected since it is not present in ROS typestore
MALFORMED_METADATA
class-attribute
instance-attribute
¶
Status indicating the Topic has been rejected since its bridge metadata ('ros' or 'mcap') is malformed
UNRESOLVED_DECODER
class-attribute
instance-attribute
¶
Status indicating the Channel has been rejected since its encoding does not have an implemented decoder
UNAVAILABLE_SCHEMA
class-attribute
instance-attribute
¶
Status indicating the Channel has been rejected since it does not contain any schema information
to_color ¶
Returns the Rich color string used to render this status in the progress UI.