ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A answers.ros.org

Rosbags - the pure python library for everything rosbag

Hi all,

I’d like to announce rosbags, a pure python library giving read-write access to rosbag1 and rosbag2 files including their conversion.

Rosbags does not have any dependencies on the ROS software stacks and can be used on its own or alongside ROS1 or ROS2. It is available from PyPI for easy installation.

It currently contains:

  • rosbag2 reader and writer,
  • rosbag1 reader for raw messages,
  • extensible type system with serializers and deserializers,
  • efficient converter between rosbag1 and rosbag2,

We’d be happy to learn your use cases.

Cheers,
Florian

25 Likes

Will this work with any rosbag2 backend, or just the sqlite3 backend?

3 Likes

Does this work with custom messages and actions?

Edit: not to pile on :slight_smile: This is awesome either way and this is definitely a “doable” additional feature even if its not in there today.

2 Likes

@gbiggs So far only the sqlite3 backend is supported. We’ll add other backends as needed. Do you have a specific one in mind?

@smac The converter from rosbag1 to rosbag2 works out-of-the-box with custom message types as it does not deserialize but converts one serialization into the other. In order to deserialize custom rosbag2 messages they need to be registered first. This happens during runtime without extra build step. For more information see: Type system — Rosbags documentation

1 Like

Not in particular, but that sort of pluggability is an important feature of rosbag2.

@chaoflow hi,I try to deserialize a custom message after register the type with get_types_from_msg() ,register_types() API like the tutorial; but when use deserialize_cdr(),there comes error like

'line 32, in deserialize_cdr
message, pos = func(rawdata[4:], 0, msgdef.cls)
File “”, line 21, in deserialize_cdr
UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xbf in position 7: invalid start byte

the custom msg is simple only include two types:

int64 a
string data

here is the error screen shot
Screenshot from 2021-06-18 11-34-46

could you give me some advice? thanks

@zhiwei_chen Could you open an issue please and attach the files so we can reproduce?

sure, i have open an issue in gitlab, you can review it with the code and msg file.

Please excuse my ignorance, but how do I install the referenced CLI tool, rosbags.convert? I cannot find any instructions in your documentation for how to install. Convert Rosbag1 to Rosbag2 — Rosbags documentation

@pmchale There is no dedicated installation of the CLI tool needed. It will be installed as part of

pip install rosbags

described in the “Getting started section” Rosbags — Rosbags documentation

Strange, it doesn’t seem to be working for me

pmchale@Alpha:~/data/ouster$ pip install rosbags
Requirement already satisfied: rosbags in /home/pmchale/.local/lib/python3.8/site-packages (0.9.0)
Requirement already satisfied: zstandard in /home/pmchale/.local/lib/python3.8/site-packages (from rosbags) (0.15.2)
Requirement already satisfied: ruamel.yaml in /home/pmchale/.local/lib/python3.8/site-packages (from rosbags) (0.17.9)
Requirement already satisfied: numpy in /usr/lib/python3/dist-packages (from rosbags) (1.17.4)
Requirement already satisfied: lz4 in /usr/lib/python3/dist-packages (from rosbags) (3.0.2+dfsg)
Requirement already satisfied: ruamel.yaml.clib>=0.1.2; platform_python_implementation == “CPython” and python_version < “3.10” in /home/pmchale/.local/lib/python3.8/site-packages (from ruamel.yaml->rosbags) (0.2.2)
pmchale@Alpha:~/data/ouster$ rosbags-convert ouster_lidar_imu_ros_3.bag
rosbags-convert: command not found

@pmchale I believe you don’t have /home/pmchale/.local/ in PATH, try

export PATH=$PATH:~/.local/bin