MCAP libraries for Python
Project description
MCAP Python Library
This library provides classes for reading and writing the MCAP file format.
Reader Example
from mcap.mcap0.stream_reader import StreamReader
stream = open("example.mcap", "rb")
reader = StreamReader(stream)
for record in reader.records:
print(record)
Writer Example
from time import time_ns
import json
from mcap.mcap0.writer import Writer
stream = open("example.mcap", "wb")
writer = Writer(stream)
# The library argument help identify what tool wrote the file.
writer.start(profile="x-custom", library="my-writer-v1")
schema_id = writer.register_schema(
name="sample",
encoding="jsonschema",
data=json.dumps({
"type": "object",
"properties": {
"sample": {
"type": "string",
}
}
}).encode()
)
channel_id = writer.register_channel(
schema_id=schema_id,
topic="sample_topic",
message_encoding="json",
)
writer.add_message(
channel_id=channel_id,
log_time=time_ns(),
data=json.dumps({"sample": "test"}).encode('utf-8'),
publish_time=time_ns(),
)
writer.finish()
stream.close()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mcap-0.0.4.tar.gz
(11.3 kB
view hashes)
Built Distribution
mcap-0.0.4-py3-none-any.whl
(13.8 kB
view hashes)