{"library":"mcap-protobuf-support","title":"MCAP Protobuf Support for Python","description":"This package provides Protobuf support for the Python MCAP library, enabling seamless reading and writing of Protobuf-encoded messages to MCAP files. MCAP is a modular, performant, and serialization-agnostic container file format, widely adopted in robotics for pub/sub data logging applications. The library is actively developed and maintained by Foxglove, with regular releases across the broader MCAP ecosystem.","language":"python","status":"active","last_verified":"Fri May 15","install":{"commands":["pip install mcap-protobuf-support"],"cli":null},"imports":["from mcap_protobuf.reader import read_protobuf_messages","from mcap_protobuf.writer import Writer"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import sys\nfrom mcap_protobuf.writer import Writer\nfrom mcap_protobuf.reader import read_protobuf_messages\n\n# Assuming you have a compiled protobuf message, e.g., 'my_message_pb2.py'\n# from my_message_pb2 import SimpleMessage, ComplexMessage\n\n# For demonstration, we'll create dummy classes that mimic protobuf messages\nclass SimpleMessage:\n    def __init__(self, data):\n        self.data = data\n    def SerializeToString(self):\n        return f'SimpleMessage(data=\"{self.data}\")'.encode('utf-8') # Dummy serialization\n    @classmethod\n    def FromString(cls, data):\n        # Dummy deserialization - in a real scenario, this would parse protobuf bytes\n        import re\n        match = re.search(r'data=\"([^\"]+)\"', data.decode('utf-8'))\n        return cls(match.group(1)) if match else cls('N/A')\n\nclass ComplexMessage:\n    def __init__(self, fieldA, fieldB):\n        self.fieldA = fieldA\n        self.fieldB = fieldB\n    def SerializeToString(self):\n        return f'ComplexMessage(fieldA=\"{self.fieldA}\", fieldB=\"{self.fieldB}\")'.encode('utf-8') # Dummy serialization\n    @classmethod\n    def FromString(cls, data):\n        # Dummy deserialization\n        import re\n        match = re.search(r'fieldA=\"([^\"]+)\".*fieldB=\"([^\"]+)\"', data.decode('utf-8'))\n        return cls(match.group(1), match.group(2)) if match else cls('N/A', 'N/A')\n\n# To make this runnable without actual .proto compilation, we need to mock\n# how the `Writer` would register these messages. In a real scenario, \n# SimpleMessage and ComplexMessage would be actual protobuf generated classes.\n\n# ---- Writing MCAP file with Protobuf messages ----\noutput_file = \"example.mcap\"\nwith open(output_file, \"wb\") as f, Writer(f) as mcap_writer:\n    # In a real application, SimpleMessage would be from `your_proto_file_pb2`\n    mcap_writer.write_message(\n        topic=\"/simple_messages\",\n        message=SimpleMessage(data=\"Hello MCAP protobuf world #1!\"),\n        log_time=1000,\n        publish_time=1000,\n    )\n    complex_message = ComplexMessage(fieldA=\"Field A 1\", fieldB=\"Field B 1\")\n    mcap_writer.write_message(\n        topic=\"/complex_messages\",\n        message=complex_message,\n        log_time=2000,\n        publish_time=2000,\n    )\nprint(f\"Wrote messages to {output_file}\")\n\n# ---- Reading MCAP file with Protobuf messages ----\ndef register_dummy_message_classes(reader):\n    # This function mocks how actual protobuf message classes would be registered\n    # For real use, you'd import your compiled protobuf message classes\n    reader.register_message(\"SimpleMessage\", SimpleMessage)\n    reader.register_message(\"ComplexMessage\", ComplexMessage)\n\n\nprint(f\"\\nReading messages from {output_file}:\")\nfor msg_info in read_protobuf_messages(output_file):\n    # The msg_info.proto_msg will be an instance of your actual Protobuf class\n    print(f\"Topic: {msg_info.topic}, Message: {msg_info.proto_msg.data if hasattr(msg_info.proto_msg, 'data') else msg_info.proto_msg.fieldA}\")\n\n","lang":"python","description":"This quickstart demonstrates how to write and read Protobuf messages to/from an MCAP file using `mcap-protobuf-support`. Before running, you would typically compile your `.proto` files into Python classes using `protoc` (e.g., `protoc --python_out=. your_message.proto`). The example uses dummy classes to simulate compiled Protobuf messages for executability. The `Writer` automatically handles schema registration, and `read_protobuf_messages` iterates through decoded messages.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-15","installed_version":"0.5.4","pypi_latest":"0.5.4","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":50,"avg_install_s":2.4,"avg_import_s":0.13,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"mcap-protobuf-support","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"mcap-protobuf-support","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"noisy","install_time_s":2.6,"import_time_s":0.08,"mem_mb":4.2,"disk_size":"49M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"mcap-protobuf-support","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"mcap-protobuf-support","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"noisy","install_time_s":2.4,"import_time_s":0.16,"mem_mb":4.7,"disk_size":"52M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"mcap-protobuf-support","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"mcap-protobuf-support","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"noisy","install_time_s":2.1,"import_time_s":0.15,"mem_mb":4.7,"disk_size":"43M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"mcap-protobuf-support","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"mcap-protobuf-support","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"noisy","install_time_s":2.1,"import_time_s":0.15,"mem_mb":5.1,"disk_size":"43M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"mcap-protobuf-support","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"mcap-protobuf-support","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"noisy","install_time_s":3,"import_time_s":0.12,"mem_mb":4.1,"disk_size":"49M"}]}}