Skip to main content

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 dict instead 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

  1. Create and activate a virtual environment:

    python -m venv .venv
    source .venv/bin/activate
    
  2. Install project and development dependencies:

    pip install -e '.[dev]'
    
  3. 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
    
  4. Run tests with pytest:

    pytest
    

Building the wheel

  1. Clean old artifacts:

    rm -rf dist
    
  2. Install the build backend:

    python -m pip install --upgrade build
    
  3. Build the wheel:

    python -m build
    
  4. (Optional) Verify the wheel locally:

    python -m pip install dist/mcap_ros2idl_support-<version>-py3-none-any.whl
    
  5. (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 package
    • cdr/ – helpers for reading and writing CDR streams
    • ros2idl_parser/ – parser for ros2idl schema definitions
    • rosmsg/ – parser for classic .msg message definitions
    • rosmsg2_serialization/ – utilities for decoding CDR payloads into dictionaries
    • decode_factory.py – integrates parsers and CDR readers with the MCAP decoder
  • examples/ – example CLI demonstrating how to iterate decoded messages
  • tests/ – unit tests for the library

Design notes

  • Uses Foxglove’s @foxglove/ros2idl-parser to handle .idl files in addition to classic .msg definitions.
  • 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

mcap_ros2idl_support-0.1.2.tar.gz (36.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcap_ros2idl_support-0.1.2-py3-none-any.whl (44.1 kB view details)

Uploaded Python 3

File details

Details for the file mcap_ros2idl_support-0.1.2.tar.gz.

File metadata

  • Download URL: mcap_ros2idl_support-0.1.2.tar.gz
  • Upload date:
  • Size: 36.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for mcap_ros2idl_support-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d8ea2c3f0c977c33e91b762a8a2f7f237ba7d7ff271c99171e23b3ef3b33ac7a
MD5 f62de242386fafa0d9ee7ffebe28a919
BLAKE2b-256 67df1b7be96d6e9ed6ed4f49ec77784fb8b786a37621e5d60c65b2aad1314d30

See more details on using hashes here.

File details

Details for the file mcap_ros2idl_support-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for mcap_ros2idl_support-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7de9d4f0a98e4636982852146d2c421ba0c56e704bbf6918180e816afe3099c0
MD5 9c3ba7dcd5750caae2706b9ae7749253
BLAKE2b-256 be8d105959c06ac9aba4e2970f3ebe9c9eeb40a52cec40865f95f00a68b24415

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page