Skip to main content

Python MCAP protobuf support

This package provides protobuf support for the Python MCAP file format reader.

Installation

Install via Pipenv by adding mcap-protobuf-support to your Pipfile or via the command line:

pipenv install mcap-protobuf-support

MCAP protobuf writing example

First, compile each of your message definitions:

protoc complex_message.proto --python_out . -o complex_message.fds
protoc simple_message.proto --python_out . -o simple_message.fds

Next, use those message definitions to register schema in the mcap file. Note that the names of the messages in the proto files must correspond to the schema names in the mcap file. For example, the message type SimpleMessage in the .proto file must be registered as an mcap schema with the name SimpleMessage.

from pathlib import Path
from typing import IO, Any

from mcap.mcap0.writer import Writer as McapWriter

from .complex_message_pb2 import ComplexMessage
from .simple_message_pb2 import SimpleMessage

output = open("example.mcap", "wb")
mcap_writer = McapWriter(output)
mcap_writer.start(profile="protobuf", library="test")

simple_schema_id = mcap_writer.register_schema(
    name="SimpleMessage",
    encoding="protobuf",
    data=(Path(__file__).parent / "simple_message.fds").read_bytes(),
)

complex_schema_id = mcap_writer.register_schema(
    name="ComplexMessage",
    encoding="protobuf",
    data=(Path(__file__).parent / "complex_message.fds").read_bytes(),
)

simple_channel_id = mcap_writer.register_channel(
    topic="/simple_message",
    message_encoding="protobuf",
    schema_id=simple_schema_id,
)

complex_channel_id = mcap_writer.register_channel(
    topic="/complex_message",
    message_encoding="protobuf",
    schema_id=complex_schema_id,
)

for i in range(1, 11):
    simple_message = SimpleMessage(data=f"Hello MCAP protobuf world #{i}!")
    mcap_writer.add_message(
        channel_id=simple_channel_id,
        log_time=i * 1000,
        data=simple_message.SerializeToString(),
        publish_time=i * 1000,
    )
    complex_message = ComplexMessage(fieldA=f"Field A {i}", fieldB="Field B {i}")
    mcap_writer.add_message(
        channel_id=complex_channel_id,
        log_time=i * 1000,
        data=complex_message.SerializeToString(),
        publish_time=i * 1000,
    )

mcap_writer.finish()
output.close()

MCAP protobuf decoding example

from mcap.mcap0.stream_reader import StreamReader
from mcap_protobuf.decoder import Decoder

reader = StreamReader("my_data.mcap")
decoder = Decoder(reader)
for m in decoder.messages:
    print(m)

Stay in touch

Join our Slack channel to ask questions, share feedback, and stay up to date on what our team is working on.

Metadata

Release files for mcap-protobuf-support 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcap-protobuf-support 0.0.3
File Size Uploaded
mcap-protobuf-support-0.0.3.tar.gz 7.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mcap-protobuf-support 0.0.3
File Interpreter ABI Platform
mcap_protobuf_support-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 18.0 kB

Release files / mcap-protobuf-support-0.0.3.tar.gz

Download URL mcap-protobuf-support-0.0.3.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
47a2719bdd242f9d97562df69bf0c542596bd9c670867e607726c6fc50c28ec4
BLAKE2b-256 checksum
How to use checksums
76a3d779ef69e808e6a21353711a75ed18ea692862eec5d48af2d3d6e5edc14f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

Release files / mcap_protobuf_support-0.0.3-py3-none-any.whl

Download URL mcap_protobuf_support-0.0.3-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cbe05accf3d9a5ff88fdd483a3dd4aa36a244d110705bbb517e284f5c90aa7a2
BLAKE2b-256 checksum
How to use checksums
fd2c538f494f25c1c759cb294bb11852164d9bb272b5ab40438852ad7a9aa1c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

Release history Release notifications | RSS feed

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

This release

0.0.3 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page