Simple utility to export tables from a sqlite3 database (generated from a ROS bag) to CSV.
This repository contains a tiny CLI helper (read_bag.py) that lists tables from a sqlite3 database and exports a selected table to a CSV file.
- List tables in a sqlite3 database
- Export a chosen table to
<table>.csv(writes header row)
- Python 3.7+
- Standard library only (no external dependencies)
The script uses the built-in sqlite3 module, argparse, and csv.
Place your sqlite3 database file (for example, a ROS bag-derived database) somewhere accessible and run the script.
Show available tables:
python3 read_bag.py --db /path/to/your/dbfile.db3 --listExport a table to CSV (writes TABLE_NAME.csv in the output directory):
python3 read_bag.py --db /path/to/your/dbfile.db3 --table TABLE_NAME --out /path/to/outdirNotes:
- If
--outis omitted the CSV is written to the current directory. - If
--dbis omitted the script uses a project-local default path embedded in the script; pass--dbto select a different database.
The script uses numeric exit codes to indicate error types. Common values:
- 0: success
- 1: invalid usage (e.g. missing
--tableand not using--list) - 2: requested table not found or no tables available
- 3: database file not found
- 4: could not open database
- 5: error checking table existence
- 6: error querying database
- 7: error writing CSV file
Small, focused pull requests are welcome. If you want to:
- Add unit tests, please use pytest and add a minimal test that runs quickly.
- Switch to a more ROS-native workflow (for example, using
rosbag2tooling) open an issue first to discuss scope.
Planned improvements and areas for future work:
- Decode CDR-serialized message payloads before export: many ROS message fields are stored in CDR (Common Data Representation). Adding a deserialization step will produce human-readable fields that can be written to CSV columns rather than raw binary blobs.
- Organize CSV outputs by topic: write CSV files grouped by ROS topic (for example, one CSV per topic or topic-named subdirectories) so data from different topics stays separated and easy to consume.
- Add caching / buffering for large datasets: introduce an in-memory or on-disk cache and batch-writing strategy to improve throughput and reduce memory pressure when exporting large databases.
MIT License — see LICENSE (not included). If you want a different license, please open an issue.
Open issues / pull requests in the project repository.