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.11.tar.gz (16.5 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.11-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mcap-0.0.11.tar.gz
  • Upload date:
  • Size: 16.5 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.11.tar.gz
Algorithm Hash digest
SHA256 4fbe0e33372f51c8a46ee251e99601cdd20c9268f9fcdf77a9bc5a19f1230464
MD5 390641d4028bea44f376dac3ab0bdaf0
BLAKE2b-256 c395783fd7a5c6a9d6478a32df9bb32b13ab093de4554a5885554534dd045bec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mcap-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 21.0 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.11-py3-none-any.whl
Algorithm Hash digest
SHA256 516acdff6303c4896c91da7ffc216a8542323cabb77dcaa04c73d432ae9d651b
MD5 3b521e9c3bb881129845d7cfb5e1608a
BLAKE2b-256 3f1f952c8efa747b65e113003b5f11c7d145e80062df0cbb5716887ac96ab9e1

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