Getting local rotation in python I'm using blender to visualize data from an orientation sensor, and would like to display the current rotation, but about the local axis. I can get the local axis just fine, but what I'm interested in is the actual rotation quaternion associated with the local rotation (how much the object has rotated over each local axis). I don't want to actually rotate anything, just display what the current local rotation is.

Is there a proper way to do this with bpy or mathutils? Or will I have to come up with my own method of determining the local rotation?
Blender's objects have three rotation values, rotation_euler, rotation_quaternion and rotation_axis_angle with the rotation_mode property defining which one is used.

If euler rotation is used and you want the quaternion rotation you can use to_quaternion() to convert it. Quaternion values also have to_axis_angle() and to_euler() if you need to convert the other way. The mathutils module contains some extras.

Note that euler values are stored as radians so you will want to use math.degrees() to get the degrees of each rotation. Both index and property access are available for euler and quaternion rotation values.

if 'Z' in bpy.data.objects['Cube'].rotation_mode:
    r = bpy.data.objects['Cube'].rotation_euler
    print(math.degrees(r[0])) # 0=X, 1=Y, 2=Z
    print(math.degrees(r.x))

    q = r.to_quaternion()
    print(q[0]) # 0=W, 1=X, 2=Y, 3=Z