"Compress" a transform hierarchy My scene consists of a Null, key-framed rotation on itself, with a cube as child. The cube is translated at (6,0,0) and has a key-framed rotation along the x-axis.

What I would like is to bake or compress (not sure of the right term here) the transform hierarchy. The end result is the cube, moving exactly like when it was the child of the Null, with the offset, but now, it's not the child of the Null any more.

And if there's a way to do it with Python, that would be a must!
This is non-trivial.  For an arbitrary animation, you would basically have to evaluate the data_paths at every frame and insert a keyframe.  For a rotating cube you would have to give it both rotation and location keyframes.

For an example of how sticky this can become, consider the similar http://web.purplefrog.com/~thoth/blender/python-cookbook/snapshot-keyframes-as-mesh.html, which I do not include inline because it does not actually solve your problem, it is just an example of how things can get messy when you have to step frame by frame and coerce blender to apply (for lack of a better word:) stuff.

For the special case of rotations, you can use sinusoidal easing (on the t menu of the fcurves editor) to animate the location of the cube as long as it always rotates in 90 degree sweeps.

Another trick for the limited case would be to change the origin of the cube's mesh to be where the empty used to be and then rotate the cube.