Skip to main content

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.reader import make_reader

with open("example.mcap", "rb") as f:
    reader = make_reader(f)
    for schema, channel, message in reader.iter_messages(topics=["/diagnostics"]):
        print(f"{channel.topic} ({schema.name}): {message.data}")

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 helps 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


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.10.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

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

mcap-0.0.10-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file mcap-0.0.10.tar.gz.

File metadata

  • Download URL: mcap-0.0.10.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for mcap-0.0.10.tar.gz
Algorithm Hash digest
SHA256 8e45a85f9bcf619a945ced306c058aca085183d7c6b14c46080bfa74909fbc1d
MD5 b3d12466bfd1a1de99453cf05e3c68a3
BLAKE2b-256 fbfe8d93c643602019d62a46e6883b32daff9d3cb3e2a0dd08ece9039375cecc

See more details on using hashes here.

File details

Details for the file mcap-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: mcap-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for mcap-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 30f12a2fa85770236ed94c833439c4310dae09a5125a97c868e61bd3fd71ed5e
MD5 ab67a25ad8c712f7e802764fc68201c8
BLAKE2b-256 23d9ad0fa16ff863eae7055327fc054af08cb9b9f4153c8d391fd8aeb019bb0f

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