Get data from the user persp view

How can I get data (in my case the euler rotation) from the user view in the viewport the cursor is hovering ?
Just to clear things up, I’m not talking about a camera object but the view you see when you’re out of the camera.

import bpy

for i in bpy.data.screens[0].areas:    # or bpy.data.screens[3].areas
    if i.type == 'VIEW_3D':
        s = i.spaces.active.region_3d
        print(s.view_rotation)

If the context is a VIEW_3D there’s no need to loop over the other areas…
one can go directly to bpy.context.region_data.

more to read:https://docs.blender.org/api/blender_python_api_master/bpy.types.RegionView3D.html?highlight=regionview3d#bpy.types.RegionView3D

Thank you guys ! The context version is what I needed. So I guess it can’t be Euler though ?

.view_matrix.to_euler() funtion

Thanks Secrop for your help on IRC.
The best-fitting command for my case was :


context.region_data.view_matrix.transposed()

I used it in this add-on of which I just finished the first working version :