A Python library to read and parse ROS 2 MCAP bag files without a ROS 2 runtime.
Project description
mcap-ros2idl-support
A Python library to read and parse ROS 2 MCAP bag files without a ROS 2 runtime. It extracts schemas from rosbag2 messages and decodes their CDR payloads.
Features
- Read-only parsing of MCAP/rosbag2 files without needing a ROS 2 runtime
- Treats each struct as a Python
dictinstead of generating dynamic classes
Installation
Requires Python ≥3.10.
Install the Python package:
pip install .
Usage
Python example
from mcap.reader import make_reader
from mcap_ros2idl_support import Ros2DecodeFactory
factory = Ros2DecodeFactory()
with open("sample.mcap", "rb") as f:
reader = make_reader(f, decoder_factories=[factory])
for decoded in reader.iter_decoded_messages():
print(decoded.channel.topic)
print(decoded.decoded_message)
Command line
python examples/cli.py --mcap-file sample.mcap
Use the --enum-as-string flag to return enumeration values as strings:
python examples/cli.py --mcap-file sample.mcap --enum-as-string
Development
-
Create and activate a virtual environment:
python -m venv .venv source .venv/bin/activate
-
Install project and development dependencies:
pip install -e '.[dev]'
-
Install and run
pre-commit:pre-commit install pre-commit run --files <file> [<file> ...]
To check the entire repository, use:
pre-commit run --all-files
-
Run tests with
pytest:pytest
Building the wheel
-
Clean old artifacts:
rm -rf dist
-
Install the build backend:
python -m pip install --upgrade build
-
Build the wheel:
python -m build
-
(Optional) Verify the wheel locally:
python -m pip install dist/mcap_ros2idl_support-<version>-py3-none-any.whl
-
(Optional) Upload to PyPI:
python -m pip install --upgrade twine python -m twine upload dist/*
Project structure
The repository is organized as follows:
mcap_ros2idl_support/– core Python packagecdr/– helpers for reading and writing CDR streamsros2idl_parser/– parser forros2idlschema definitionsrosmsg/– parser for classic.msgmessage definitionsrosmsg2_serialization/– utilities for decoding CDR payloads into dictionariesdecode_factory.py– integrates parsers and CDR readers with the MCAP decoder
examples/– example CLI demonstrating how to iterate decoded messagestests/– unit tests for the library
Design notes
- Uses Foxglove’s
@foxglove/ros2idl-parserto handle.idlfiles in addition to classic.msgdefinitions. - MCAP file writing is not supported, though CDR encoding helpers are available for individual messages.
- Enumerations defined in IDL can be returned as their string values by
enabling
enum_as_string. - The goal is to enable parsing MCAP bags without any ROS 2 dependencies to make offline analysis easier.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcap_ros2idl_support-0.1.3.tar.gz.
File metadata
- Download URL: mcap_ros2idl_support-0.1.3.tar.gz
- Upload date:
- Size: 36.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9143fb1966d5257ab5e9f881b0b34118725adda2ac6866f1516af2418d51d19
|
|
| MD5 |
3524267b9923d027a5eb84a48e57d665
|
|
| BLAKE2b-256 |
b42d40633a002c1b095e1789121c5fb04877a6665ab81135b468264a81d8895c
|
File details
Details for the file mcap_ros2idl_support-0.1.3-py3-none-any.whl.
File metadata
- Download URL: mcap_ros2idl_support-0.1.3-py3-none-any.whl
- Upload date:
- Size: 44.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22b6102344a70319c641b955c81f5bde690e399e8d54870086b01ca426ea8672
|
|
| MD5 |
1d348c6a93c8d97dacfc93b166ac07a8
|
|
| BLAKE2b-256 |
e48d8f844a2b6c551a055e3effb4d891c3a88f712e75e0c3848e71cc8c48a441
|