{"library":"rosbags","title":"Rosbags","description":"Rosbags is a pure Python library designed to read, modify, convert, and write rosbag files for both ROS 1 and ROS 2. It offers high-level interfaces, support for various rosbag formats (rosbag1 and rosbag2), an extensible type system with serializers and deserializers, and efficient conversion capabilities. The library is actively maintained with regular releases. The current version is 0.11.0.","language":"python","status":"active","last_verified":"Sat May 16","install":{"commands":["pip install rosbags"],"cli":{"name":"rosbags","version":"sh: 1: rosbags: not found"}},"imports":["from rosbags.highlevel import AnyReader","from rosbags.typesys import Stores","from rosbags.typesys import get_typestore","from rosbags.rosbag2 import Reader","from rosbags.serde import Serde"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"from pathlib import Path\nfrom rosbags.highlevel import AnyReader\nfrom rosbags.typesys import Stores, get_typestore\n\n# Replace with the actual path to your rosbag file/directory\n# For testing, you can create a dummy bag file or use an existing one.\n# Example: bagpath = Path('./path/to/my_rosbag')\n# Ensure the path points to the directory containing a ROS2 bag or a ROS1 .bag file.\nbagpath = Path('test_rosbag_dir') # Placeholder, modify as needed\n\n# Create a type store to use if the bag has no message definitions or for custom types.\n# ROS2_FOXY is an example; choose the appropriate ROS distribution if needed.\ntypestore = get_typestore(Stores.ROS2_FOXY)\n\ntry:\n    # Create reader instance and open for reading.\n    with AnyReader([bagpath], default_typestore=typestore) as reader:\n        # Filter connections (topics) if desired. Here, we read all messages.\n        # connections = [x for x in reader.connections if x.topic == '/imu_raw/Imu']\n        \n        print(f\"Found {len(reader.connections)} connections (topics) in the bag.\")\n        for connection in reader.connections:\n            print(f\"  Topic: {connection.topic}, Type: {connection.msgtype}\")\n\n        message_count = 0\n        for connection, timestamp, rawdata in reader.messages():\n            # Deserialize the message data\n            msg = reader.deserialize(rawdata, connection.msgtype)\n            # Access message fields (example for a common message type)\n            # This assumes your message type has a 'header' and 'frame_id'\n            # Adapt based on the actual message types in your bag.\n            try:\n                if hasattr(msg, 'header') and hasattr(msg.header, 'frame_id'):\n                    print(f\"[{timestamp}] Topic: {connection.topic}, Frame ID: {msg.header.frame_id}\")\n                else:\n                    print(f\"[{timestamp}] Topic: {connection.topic}, Message: {msg}\")\n            except AttributeError:\n                print(f\"[{timestamp}] Topic: {connection.topic}, Message: {msg}\") # Fallback for messages without header\n            message_count += 1\n            if message_count >= 10: # Limit output for brevity\n                print(\"... (truncated after 10 messages)\")\n                break\nexcept FileNotFoundError:\n    print(f\"Error: Bag file or directory not found at {bagpath}. Please create or specify a valid path.\")\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to open a rosbag file (ROS1 or ROS2), iterate through its messages, and deserialize them using the high-level `AnyReader` interface. It includes explicit handling for type stores, which is crucial for correct message deserialization, especially if the bag does not contain complete message definitions or for custom message types. Remember to replace `test_rosbag_dir` with the actual path to your rosbag.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-16","installed_version":"0.9.23","pypi_latest":"0.11.2","is_stale":true,"summary":{"python_range":"3.10–3.9","success_rate":50,"avg_install_s":4.7,"avg_import_s":0.27,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"rosbags","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"rosbags","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":5,"import_time_s":0.2,"mem_mb":7.9,"disk_size":"128M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"rosbags","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"rosbags","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":4.7,"import_time_s":0.3,"mem_mb":8.8,"disk_size":"136M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"rosbags","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"rosbags","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":4.4,"import_time_s":0.28,"mem_mb":8.3,"disk_size":"124M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"rosbags","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"rosbags","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":4.5,"import_time_s":0.21,"mem_mb":7.1,"disk_size":"123M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"rosbags","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"rosbags","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":5.1,"import_time_s":0.35,"mem_mb":7,"disk_size":"126M"}]}}