Skip to content

Software

classic_bags

By MetroRobots, from github.com/MetroRobots/classic_bags (opens in a new tab)

  • Middleware
  • Library
  • BSD-3-Clause

A Python and C++ library giving a ROS 1 style interface for reading and writing ROS 2 bag files, so code written for rosbag can be ported with few changes.

Facts

GitHub stars
10read on 27 Nov 2026
Last update
21 Jul 2026Newest commit on main
Maintenance
Maintaineda commit in the last 12 months
Difficulty
Beginner

Checked on GitHub on 28 Nov 2026.

Licenses

Code
BSD-3-Clause (opens in a new tab)

Read by Robotheca from LICENSE (opens in a new tab) (BSD-3-Clause) at commit d65e6a7 (opens in a new tab), on 16 Oct 2026.

Commercial use
Yes

At a glance

What it is
  • Reads messages from a bag file, optionally filtered by topic, in a style matching the ROS 1 rosbag API.
  • Writes messages to a bag file with an explicit timestamp given as a float, integer nanoseconds, rclpy time, or a message time, or the system time by default.
  • Provides a Bag class in both Python and C++ with open, read and write modes.
  • The C++ reader does not yet support topic filtering or iterators; it uses hasNext and next instead.
  • Closing the bag is optional in Python, since the bag is closed automatically when no longer needed.

Robotheca's summary of the project's documents, not the creator's words.

Robots on Robotheca
No robot on Robotheca uses it yet.
Licence
BSD-3-Clause. Commercial use: Yes. Where it was read
Install
In the creator's words: The project's README (opens in a new tab)
Maintenance
Maintained, last commit on 21 Jul 2026.

Use it

How to install it, in the creator's words: The project's README (opens in a new tab)

Robotheca doesn't review code. Read it before running it.

Files and versions

Facts read at commit d65e6a7

Robotheca never hosts the code: each link goes to the creator's own page.

The README

The creator's own README, copied as written: README.md by MetroRobots, at commit d65e6a7, under BSD-3-Clause (opens in a new tab). The original on GitHub (opens in a new tab).

Read the README here

classic_bags

Simplified ROS 2 interface in the style of ROS 1 for reading and writing bag files

Reading Python
ROS 1 Code
import rosbag
bag = rosbag.Bag('test.bag')
for topic, msg, t in bag.read_messages(topics=['chatter', 'numbers']):
    print(msg)
bag.close()
ROS 2 Code
import classic_bags
bag = classic_bags.Bag('test.bag')
for topic, msg, t in bag.read_messages(topics=['chatter', 'numbers']):
    print(msg)
# bag.close() Closing bag is not necessary
Writing Python
ROS 1 Code
import rosbag
from std_msgs.msg import Int32, String

bag = rosbag.Bag('test.bag', 'w')

try:
    s = String()
    s.data = 'foo'

    i = Int32()
    i.data = 42

    bag.write('chatter', s)
    bag.write('numbers', i)
finally:
    bag.close()
ROS 2 Code
import classic_bags
from std_msgs.msg import Int32, String

bag = classic_bags.Bag('test.bag', 'w')

try:
    s = String()
    s.data = 'foo'

    i = Int32()
    i.data = 42

    bag.write('chatter', s)
    bag.write('numbers', i)
finally:
    bag.close()  # Closing is not strictly necessary
Alternate ROS 2 Code
import classic_bags
from std_msgs.msg import String
import rclpy.time
import builtin_interfaces.msg


with classic_bags.Bag('test.bag', 'w') as bag:
    s = String()
    s.data = 'foo'

    # The third argument of the write method is the timestamp

    # Floats are interpreted as seconds since epoch
    bag.write('chatter', s, 456606000.5)

    # Ints are interpreted as nanoseconds since epoch
    bag.write('chatter', s, 456606000600000000)

    # You can also use rclpy.time.Time
    pytime = rclpy.time.Time(seconds=456606000, nanoseconds=700000000)
    bag.write('chatter', s, pytime)

    # Or a timestamp from a message
    msgtime = builtin_interfaces.msg.Time()
    msgtime.sec = 456606000
    msgtime.nanosec = 800000000
    bag.write('chatter', s, msgtime)

    # If none is specified, the system time will be used
    bag.write('chatter', s)
C++ Reading
ROS 1 Code
#include <rosbag/bag.h>
#include <rosbag/view.h>
#include <std_msgs/Int32.h>
#include <std_msgs/String.h>

#include <boost/foreach.hpp>
#define foreach BOOST_FOREACH

rosbag::Bag bag;
bag.open("test.bag", rosbag::bagmode::Read);

std::vector<std::string> topics;
topics.push_back(std::string("chatter"));
topics.push_back(std::string("numbers"));

rosbag::View view(bag, rosbag::TopicQuery(topics));

foreach(rosbag::MessageInstance const m, view)
{
    std_msgs::String::ConstPtr s = m.instantiate<std_msgs::String>();
    if (s != NULL)
        std::cout << s->data << std::endl;

    std_msgs::Int32::ConstPtr i = m.instantiate<std_msgs::Int32>();
    if (i != NULL)
        std::cout << i->data << std::endl;
}

bag.close();
ROS 2 Code
#include <classic_bags/bag.hpp>
#include <std_msgs/msg/string.hpp>
#include <std_msgs/msg/int32.hpp>

classic_bags::Bag bag
bag.open("test.bag", classic_bags::Read);

// Note: Topic filtering and iterator support not available yet
while (bag.hasNext())
{
    auto m = bag.next();
    std_msgs::msg::String::SharedPtr s = m->instantiate<std_msgs::msg::String>();
    if (s != NULL)
        std::cout << s->data << std::endl;

    std_msgs::msg::Int32::SharedPtr i = m->instantiate<std_msgs::msg::Int32>();
    if (i != NULL)
        std::cout << i->data << std::endl;
}

bag.close();
C++ Writing
ROS 1 Code
#include <rosbag/bag.h>
#include <std_msgs/Int32.h>
#include <std_msgs/String.h>

rosbag::Bag bag;
bag.open("test.bag", rosbag::bagmode::Write);

std_msgs::String str;
str.data = std::string("foo");

std_msgs::Int32 i;
i.data = 42;

bag.write("chatter", ros::Time::now(), str);
bag.write("numbers", ros::Time::now(), i);

bag.close();
ROS 2 Code
#include <classic_bags/bag.hpp>
#include <std_msgs/msg/string.hpp>
#include <std_msgs/msg/int32.hpp>

classic_bags::Bag bag;
bag.open("test.bag", classic_bags::Write);

std_msgs::msg::String str;
str.data = std::string("foo");

std_msgs::msg::Int32 i;
i.data = 42;

// If not specified, timestamp is assumed to be system time
bag.write("chatter", str);

// Otherwise, timestamp must be rclcpp::Time
bag.write("numbers", rclcpp::Time(456606000600000000), i);

bag.close();

Robotheca lists software as a reference: nothing is hosted or run here, and every fact links to where it was read.