rosbag has code APIs for reading and writing bags in either C++ or Python. For a description of these APIs, see rosbag Code API
For technical details on the contents of bag files, see Bag file format
Overview in addition:
The rosbag command-line tool and code APIs are stable. Every effort will be made to maintain backwards compatibility.
The main new feature being planned for rosbag is the addition of a ROS API for interacting with the playing and recording nodes via service calls.