How to toggle(Open/Close) `T` or `N` Panel in 3D view Using Python
You can use bpy.ops.wm.context_toggle(data_path) This will toggle N or 'T' panel of whatever area operator was called.
import bpy

class SimpleOperator(bpy.types.Operator):
    &quot;&quot;&quot;Tooltip&quot;&quot;&quot;
    bl_idname = &quot;object.simple_operator&quot;
    bl_label = &quot;Simple Object Operator&quot;

    @classmethod
    def poll(cls, context):
        return context.active_object is not None

    def execute(self, context):
        bpy.ops.wm.context_toggle(data_path=&quot;space_data.show_region_ui&quot;)
        return {'FINISHED'}


def register():
    bpy.utils.register_class(SimpleOperator)


def unregister():
    bpy.utils.unregister_class(SimpleOperator)


if __name__ == &quot;__main__&quot;:
    register()


If you run this script and call the operator in Text_Editor It will open this side panel.
So if you want to open/close N Panel of view3d from other areas you need to override context. It is a way to fool blender thinking that operator was called in different area.
import bpy

class SimpleOperator(bpy.types.Operator):
    &quot;&quot;&quot;Tooltip&quot;&quot;&quot;
    bl_idname = &quot;object.simple_operator&quot;
    bl_label = &quot;Simple Object Operator&quot;

    @classmethod
    def poll(cls, context):
        return context.active_object is not None

    def execute(self, context):
        #copy context
        context_copy = context.copy()
        #loop over current areas
        for area in context.screen.areas:
            #Check if there is 3d view area
            if area.type == 'VIEW_3D':
                #If yes then override context
                context_copy['area'] = area
        
        #Now pass our custom context.
        #When calling any bpy.ops operator it takes context in which it was called
        #but you can override that.
        #look here for Offical documetation : https://docs.blender.org/api/current/bpy.ops.html#overriding-context
        bpy.ops.wm.context_toggle(context_copy,data_path=&quot;space_data.show_region_ui&quot;)
        return {'FINISHED'}


def register():
    bpy.utils.register_class(SimpleOperator)


def unregister():
    bpy.utils.unregister_class(SimpleOperator)


if __name__ == &quot;__main__&quot;:
    register()


Now when you run script and call operator from text editor, it will open n panel of 3d view
HOW TO DECIDE data_path
What I do is go to edit&gt;preferences&gt;keymap
Change search type to Key-Binding and type key which is used in Blender to open/close whatever panel you want. Here I am searching for Tools or Toolbar or T panel in viewport. It can be open using T key. So I searched for it. So Operator call  will be like this : bpy.ops.wm.context_toggle(context_copy,data_path=&quot;space_data.show_region_toolbar&quot;)