Skip to main content

A Python library to work with bag files without ROS.

Project description

pybag

A Python library to work with bag files (MCAP and ROS Bag) without ROS.

[!Warning] The library is still in the early stages of development and the API is still unstable

Installation

# Add dependency to your package
uv add pybag-sdk

# Install pybag cli
uv tool install pybag-sdk

Quick Start

CLI

# Get file information
pybag info data.mcap

# Filter messages
pybag filter data.mcap -o output.mcap --include-topic /camera

# Merge multiple files
pybag merge input1.mcap input2.mcap -o output.mcap

Unified Reader

The Reader class provides a common interface for reading both MCAP and ROS 1 bag files.

The file format is automatically detected from the file extension.

from pybag import Reader

# Works with both .mcap and .bag files
with Reader.from_file("data.mcap") as reader:
    for msg in reader.messages("/camera"):
        print(msg.log_time, msg.data)

# Same API for ROS 1 bag files
with Reader.from_file("data.bag") as reader:
    for msg in reader.messages("/sensor/*"):  # glob patterns supported
        print(msg.topic, msg.msg_type, msg.data)

Reading MCAP Files

from pybag.mcap_reader import McapFileReader

with McapFileReader.from_file("data.mcap") as reader:
    for msg in reader.messages("/camera"):
        print(msg.log_time, msg.data)

Writing MCAP Files

from pybag.mcap_writer import McapFileWriter
from pybag.ros2.humble import std_msgs

with McapFileWriter.open("output.mcap") as writer:
    log_time_ns = 1000
    msg = std_msgs.String(data="hello")
    writer.write_message("/status", log_time_ns, msg)

Reading ROS 1 Bag Files

from pybag.bag_reader import BagFileReader

with BagFileReader.from_file("data.bag") as reader:
    for msg in reader.messages("/camera"):
        print(msg.log_time, msg.data)

Writing ROS 1 Bag Files

from pybag.bag_writer import BagFileWriter
from pybag.ros1.noetic import std_msgs

with BagFileWriter.open("output.bag") as writer:
    log_time_ns = 1000
    msg = std_msgs.String(data="hello")
    writer.write_message("/status", log_time_ns, msg)

Custom Messages

from dataclasses import dataclass
import pybag.types as t

@dataclass
class SensorData:
    __msg_name__ = 'custom/msg/SensorData'
    temperature: t.float32
    humidity: t.float32

with McapFileWriter.open("sensors.mcap") as writer:
    writer.write_message("/sensor", 1000, SensorData(25.5, 60.0))

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

pybag_sdk-0.8.0.tar.gz (254.2 kB view details)

Uploaded Source

Built Distribution

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

pybag_sdk-0.8.0-py3-none-any.whl (172.3 kB view details)

Uploaded Python 3

File details

Details for the file pybag_sdk-0.8.0.tar.gz.

File metadata

  • Download URL: pybag_sdk-0.8.0.tar.gz
  • Upload date:
  • Size: 254.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.20 {"installer":{"name":"uv","version":"0.9.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pybag_sdk-0.8.0.tar.gz
Algorithm Hash digest
SHA256 95576f4d0d1ead108c996e777742179d95076de6090252a79452a715adfa3e0b
MD5 e2441a2600ea16a14cf83e3c4f6b579e
BLAKE2b-256 bd553e35be27d5f14db4284710c07edf193df125329de56dac56b6f654c6f668

See more details on using hashes here.

File details

Details for the file pybag_sdk-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: pybag_sdk-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 172.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.20 {"installer":{"name":"uv","version":"0.9.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pybag_sdk-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 94bad1e6a2617dc76b1dd05171fedde35c54fbce64ac72cef3c858cb01d06434
MD5 0b2c726858ae714e82e86899bf2f4206
BLAKE2b-256 3eb98b1d989f32ca20219e42075bf856203cbbff3c4dad86514f2a265f00249e

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