Skip to main content

Python utilities for reading and writing ASAM OSI trace files (MCAP, binary .osi, text .txth)

Project description

osi-utilities (Python)

Python utilities for reading and writing ASAM OSI (Open Simulation Interface) trace files.

Supported Formats

  • MCAP (.mcap) - Multi-channel container format with metadata
  • Binary (.osi) - Single-channel binary format with length-prefixed protobuf messages
  • Text (.txth) - Human-readable protobuf TextFormat

Installation

From PyPI:

pip install asam-osi-utilities

For development (uses a virtual environment):

make setup    # creates .venv and installs in editable mode

API Entrypoints

The package exposes two API levels:

  1. Channel abstraction (simple API) via open_channel(...)
  • Use this when you want to read one logical channel and get protobuf messages directly.
  • Works across .osi and .mcap.
  1. Advanced tracefile API via create_reader(...) and concrete readers/writers
  • Use this when you need explicit control over topics, decoder mode, metadata, writer behavior, or multi-channel features.

Quick Start

1) Channel abstraction (simple API)

from pathlib import Path
from osi_utilities import ChannelSpecification, MessageType, open_channel

# Single channel from an MCAP file (explicit topic)
spec = ChannelSpecification(
    path=Path("trace.mcap"),
    topic="GroundTruthTopic",
    message_type=MessageType.GROUND_TRUTH,
)

with open_channel(spec) as channel:
    for message in channel:
        print(type(message).__name__)

Channel abstraction writing uses open_channel_writer(...):

from pathlib import Path
from osi3.osi_groundtruth_pb2 import GroundTruth
from osi_utilities import ChannelSpecification, MessageType, open_channel_writer

spec = ChannelSpecification(
    path=Path("output.osi"),
    message_type=MessageType.GROUND_TRUTH,
)

msg = GroundTruth()
msg.timestamp.seconds = 1

with open_channel_writer(spec) as channel_writer:
    channel_writer.write_message(msg)

2) Advanced reading API

from pathlib import Path
from osi_utilities import MultiTraceReader, create_reader

# Create reader by extension (.osi/.mcap/.txth), then configure explicitly
path = Path("trace.mcap")
reader = create_reader(path)

if isinstance(reader, MultiTraceReader):
    reader.set_topics(["GroundTruthTopic"])

if not reader.open(path):
    raise RuntimeError(f"Failed to open {path}")

with reader:
    for result in reader:
        print(result.message_type, result.message)

Advanced configuration helpers based on ChannelSpecification are also available in osi_utilities.tracefile.configure:

from pathlib import Path
from osi_utilities import create_reader
from osi_utilities.api import ChannelSpecification, MessageType
from osi_utilities.tracefile.configure import configure_reader, configure_reader_for_channels

path = Path("trace.mcap")
reader = create_reader(path)

# Configure from one channel spec
configure_reader(
    reader,
    ChannelSpecification(
        path=path,
        topic="GroundTruthTopic",
        message_type=MessageType.GROUND_TRUTH,
    ),
)

# Or configure from multiple channel specs (same file path)
configure_reader_for_channels(
    reader,
    [
        ChannelSpecification(path=path, topic="GroundTruthTopic", message_type=MessageType.GROUND_TRUTH),
        ChannelSpecification(path=path, topic="SensorDataTopic", message_type=MessageType.SENSOR_DATA),
    ],
)

3) Writing (advanced API)

from pathlib import Path
from osi3.osi_sensorview_pb2 import SensorView
from osi_utilities import SingleTraceWriter

sensor_view = SensorView()
sensor_view.version.version_major = 3
sensor_view.timestamp.seconds = 123
sensor_view.timestamp.nanos = 456

with SingleTraceWriter() as writer:
    writer.open(Path("output.osi"))
    writer.write_message(sensor_view)

For multi-channel MCAP writing, use MultiTraceWriter or MCAPChannel.

Development

make setup      # Create venv and install dependencies
make test       # Run tests
make lint       # Run linter
make format     # Format code
make typecheck  # Run type checker

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

asam_osi_utilities-0.4.0.tar.gz (38.3 kB view details)

Uploaded Source

Built Distribution

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

asam_osi_utilities-0.4.0-py3-none-any.whl (42.4 kB view details)

Uploaded Python 3

File details

Details for the file asam_osi_utilities-0.4.0.tar.gz.

File metadata

  • Download URL: asam_osi_utilities-0.4.0.tar.gz
  • Upload date:
  • Size: 38.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for asam_osi_utilities-0.4.0.tar.gz
Algorithm Hash digest
SHA256 c00c4fdadb00f29e6440b107488c1371499a4886b0ff16d9f63ea96ea5606632
MD5 901f7ca35d92b21794f5bdd5ea1af0fd
BLAKE2b-256 d4ecd5f41c43c5c730f450b3ac2608e0d26d00de6a2542914a6fd963fca4fb20

See more details on using hashes here.

Provenance

The following attestation bundles were made for asam_osi_utilities-0.4.0.tar.gz:

Publisher: cd_release.yml on lichtblick-suite/asam-osi-utilities

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file asam_osi_utilities-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for asam_osi_utilities-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b0392f2b1b9be6b920a5e74f78b63ad0c286b60476ce063c94caa39b1dfa1153
MD5 b5135fa5a6ddaedd45fc0c7bcace30a8
BLAKE2b-256 bc410f27c4754a785a921f0a948d669c2ce1dce4cc5d6c94d787cc5b83fe77f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for asam_osi_utilities-0.4.0-py3-none-any.whl:

Publisher: cd_release.yml on lichtblick-suite/asam-osi-utilities

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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