Changing the space type to the compositor with bpy

I can use the code below to switch the space type to the UV Editor, but i can’t figure out how to change the space type to be the compositor. The Node Editor space doesn’t have a mode property. Does any one know how to change the space to be the compositor with the bpy?

import bpy
area = bpy.context.area
area.type = 'IMAGE_EDITOR'
for space in area.spaces:
    if space.type == 'IMAGE_EDITOR':
        space.mode = 'UV'
area.ui_type = 'CompositorNodeTree'

For this kind of thing, it’s useful to make the change by hand in the ui and watch the steps in the Info editor.

Oh wow that’s much easier than what I was doing. I totally forgot about the info editor. Thanks for the information!