Registry / data / mcap-ros2-support

mcap-ros2-support

JSON →
library0.5.7pypypiunverified

mcap-ros2-support provides utilities to seamlessly integrate ROS2 messages with the MCAP data logging format. It allows for efficient recording and playback of ROS2 data within MCAP files, handling schema definition and message serialization/deserialization. The current version is 0.5.7, and the project (including core mcap, CLI, and other support libraries) has a frequent release cadence.

pip install mcap-ros2-support
INSTALL
IMPORT
SIG · MCAP-ROS2-SUPPORT
M
mcap-ros2-support
datapythonv0.5.7
Install
2.1s avg
Import
Disk
45MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5.7 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
build_error
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.1s · import 0.000s · 47MB
45MB installed
● package 45MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Ros2RawWriter
from mcap_ros2 import Ros2RawWriter
from mcap_ros2 import Ros2RawWriter

This quickstart demonstrates how to write and read a ROS2 message to and from an MCAP file using `mcap-ros2-support`. It mocks a `std_msgs/msg/String` for demonstration, but in a live ROS2 environment, you would import actual message types. It uses `Ros2RawWriter` to encode ROS2 messages into the MCAP format and `Ros2Reader` to decode them back. The core `McapWriter` is used for the underlying MCAP file operations.

import os from pathlib import Path from mcap.mcap_writer import McapWriter from mcap_ros2.writer import Ros2RawWriter from mcap_ros2.reader import Ros2Reader # Assuming a ROS2 message type is available, e.g., from an installed ROS2 package # For demonstration, we'll mock a simple message structure for 'std_msgs/msg/String' # In a real scenario, you would import the actual message type and populate it. class MockStringMsg: _TYPE = 'std_msgs/msg/String' _HAS_HEADER = False _LAYOUT = [ ('data', 'string'), ] _REGISTERED_TYPES = {} _CDR_TYPES = {} def __init__(self, data=''): self.data = data def __repr__(self): return f"MockStringMsg(data='{self.data}')" @staticmethod def get_fields_and_field_types(): return [('data', 'string')] def get_type_description_interfaces(self): # Simplified mock for the purpose of the quickstart return {'type_description': 'string data'} # Write a simple MCAP file with a ROS2 message output_file = Path('ros2_messages.mcap') with open(output_file, 'wb') as f, McapWriter(f) as mcap_writer, Ros2RawWriter(mcap_writer) as ros2_writer: # In a real ROS2 environment, you'd create actual ROS2 messages # from std_msgs.msg import String # msg = String(data='Hello ROS2 from MCAP!') mock_msg = MockStringMsg(data='Hello ROS2 from MCAP!') topic = '/chatter' log_time_ns = 123456789 # The Ros2RawWriter can infer the schema from a ROS2 message object. # For this mock, we ensure the mock_msg has the necessary _TYPE and field info. ros2_writer.write_message( topic=topic, message=mock_msg, log_time_ns=log_time_ns, publish_time_ns=log_time_ns ) print(f"Wrote ROS2 message to {output_file}") # Read the MCAP file and verify with open(output_file, 'rb') as f: reader = Ros2Reader(f) for msg, schema, channel in reader.iter_decoded_messages(): print(f"Read message from topic '{channel.topic}': {msg}") assert msg.data == 'Hello ROS2 from MCAP!' break # Only read one message for this example # Clean up the created file os.remove(output_file) print(f"Cleaned up {output_file}")
Debug
Known issues
gotchaDeserializing ROS2 messages requires the corresponding `rosidl_runtime_py` and `rosidl_typesupport_fastrtps_cpp` (or other type support) packages for the message types to be installed and available in the Python environment where the MCAP file is being read. Missing these will result in deserialization errors.
fix
Ensure all ROS2 message packages are correctly installed in your Python environment (`pip install ...` for Python packages, or `colcon build` for ROS2 workspaces).
affects: All versions
breakingPrior to v0.5.7, specifying topics might have had stricter type requirements. As of v0.5.7, topics can be specified as strings, providing more flexibility, indicated by 'allow topics specified as string' in the changelog.
fix
Update to `mcap-ros2-support>=0.5.7` to use string topics, or ensure topic inputs match previous API expectations for older versions.
affects: <0.5.7
gotchaThe `mcap_ros2` package (where `Ros2RawWriter` and `Ros2Reader` reside) is a sub-package within the `mcap-ros2-support` distribution. The import paths use `mcap_ros2` directly, which can be confusing for users expecting `mcap_ros2_support`.
fix
Always use `from mcap_ros2.<reader|writer> import <Symbol>` for the ROS2 specific components.
affects: All versions
Upgrade
Version history
0.5.7latest on PyPI · released Dec 24, 2025
Audit
Dependencies
mcaprequiredCore MCAP library for writing/reading MCAP files.
rosidl_runtime_pyrequiredProvides ROS2 message runtime definitions for Python.
rosidl_typesupport_fastrtps_cppoptionalNeeded for fast RTPS type support, often a transitive dependency.
Agent activity
36 hits · last 30 days
node
34
Resources
mcap-ros2-support — pip install mcap-ros2-support · libregistry