Skip to main content

ROS2Bag Reader

PyPI - License PyPI - Version PyPI - Python Version PyPI Downloads

A lightweight Python utility for reading ROS 2 (rosbag2) recordings stored with the default sqlite3 backend.

ROS2BagReader provides:

  • Direct access to deserialized ROS messages.
  • Convenient NumPy array extraction from message fields.
  • Flexible timestamp handling (raw, bag-relative, topic-relative).
  • Automatic support for split bag files.
  • Simple bag metadata summary.

The reader operates at the bag folder level (the directory containing metadata.yaml), not individual .db3 files.

Description

ROS 2 recordings created with:

ros2 bag record ...

generate a folder containing:

recording/
├── metadata.yaml
├── recording_0.db3
├── recording_1.db3
└── ...

ROS2BagReader:

  • Parses metadata.yaml
  • Opens all .db3 files automatically
  • Deserializes messages using rosidl_runtime_py
  • Provides NumPy-ready data extraction utilities

It is designed for data analysis, plotting, and post-processing workflows, especially inside Jupyter notebooks.

Installation

Python 3.10 or greater is required.

You can intall the module with pip using.

pip install ros2bag-reader

Or you can copy the module into your project or install it as a local package.

Dependencies

The library requires:

dependencies = [
    "numpy>=1.24.0",
    "rosidl-runtime-py>=0.9.3",
    "rclpy>=3.3.16",
    "PyYAML>=6.0.3",
    "setuptools>=82.0.0",
    "typeguard>=4.5.0",
    "jinja>=3.1.6",
]

Simple Usage Example

Example using a turtlesim recording:

from ros2bag_reader import ROS2BagReader

reader = ROS2BagReader("recording")

reader.summary()

pose = reader.get_messages("/turtle1/pose")

pose_data = reader.get_field_array(
    "/turtle1/pose",
    ["x", "y", "theta"]
)

timestamps = reader.get_time_array(
    "/turtle1/pose",
    reference="topic"
)

reader.close()

For a complete example including plotting and data visualization, see the Jupyter notebook in the examples/ folder.

Class Reference

ROS2BagReader(bag_folder: str, workspace: str)

Initialize the reader from a ROS 2 bag folder.

Parameters

  • bag_folder — Path to the directory containing metadata.yaml
  • workspace— Path to a ROS 2 workspace install directory (or its parent). When provided, all .so libraries found under it are preloaded via ctypes.CDLL. This enables deserialization of custom ROS message types (e.g., interfaces/msg/Force) that are not part of a standard ROS 2 installation, without requiring the environment to be sourced beforehand.

close()

Closes all open SQLite database connections.

Call this when finished reading the bag to release file handles.


get_messages(topic_name: str)

Retrieve all messages from a topic.

Returns

list[(timestamp_ns: int, message: ROS message instance)]

Timestamps are returned in nanoseconds since epoch.


summary()

Print a human-readable summary of the bag:

  • Storage backend
  • Duration
  • Total message count
  • Number of database files
  • Per-topic type and message count

get_time_array(topic_name: str, unit="s", reference="topic")

Return timestamps as a NumPy array.

Parameters

  • unit

    • "s" → seconds (float64)
    • "ns" → nanoseconds (int64)
  • reference

    • "topic" → relative to first message of the topic
    • "bag" → relative to bag start time
    • "raw" → no normalization (epoch time)

Returns

np.ndarray

get_field_array(topic_name: str, fields: list[str], return_timestamps=False)

Extract selected numeric fields into a NumPy array.

Supports:

  • Nested attributes using dot notation
  • Indexed access for array fields

Examples

["x", "y", "theta"]

["pose.position.x", "pose.position.y"]

["ranges[0]", "ranges[10]"]

Returns

If return_timestamps=False:

np.ndarray shape (N, len(fields))

If return_timestamps=True:

timestamps_ns, data_array

Metadata

Release files for ros2bag-reader 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ros2bag-reader 0.1.0
File Size Uploaded
ros2bag_reader-0.1.0.tar.gz 7.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ros2bag-reader 0.1.0
File Interpreter ABI Platform
ros2bag_reader-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.3 kB

Release files / ros2bag_reader-0.1.0.tar.gz

Download URL ros2bag_reader-0.1.0.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
25f815695b15b710f9c5f943c0c4034c7f5c4a9cad734323d4805630a96a7673
BLAKE2b-256 checksum
How to use checksums
d5fc3501f6a2397eb0c18b714a547b777c1cb32091bdc75318f9ca0e015a3ca8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 9, 2026.

Transparency log

Release files / ros2bag_reader-0.1.0-py3-none-any.whl

Download URL ros2bag_reader-0.1.0-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1fdc9c18125ed379dd580ea5629802d7ecff65c3f1faf23cea169a63d711e25d
BLAKE2b-256 checksum
How to use checksums
93e19aebd8485063c739ef860710709cbf269d2dce48fd6524bdc66526980070
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 9, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page