Toggle UI from python
I managed to get it working by overriding the context. So if anyone is interested, here it is:
for area in bpy.context.window.screen.areas:
        if area.type == 'VIEW_3D':
            for region in area.regions:
                if region.type == 'WINDOW':
                    override = bpy.context.copy()
                    override['area'] = area
                    override['region'] = region
                    override['scene'] = bpy.context.scene
                    bpy.ops.screen.screen_full_area(override, use_hide_panels=True)   

for area in bpy.context.window.screen.areas:
        if area.type == 'VIEW_3D':
            for region in area.regions:
                if region.type == 'WINDOW':
                    override = bpy.context.copy()
                    override['area'] = area
                    override['region'] = region
                    override['scene'] = bpy.context.scene                      
                    bpy.ops.wm.setup_ui(override)  


class MYOPERATOR_OT_setup_ui(bpy.types.Operator):
    bl_idname = &quot;wm.setup_ui&quot;
    bl_label = &quot;Setup UI&quot;

    def execute(self, context):
        context.space_data.show_region_ui = True # Opens sidebar in 3d viewport
        context.space_data.region_3d.view_perspective = 'ORTHO' # 'PERSP', 'CAMERA'. Set 3d viewport to othorgonal
        
        return {'FINISHED'}

The operator needs to be registred of cause.