How do I add a new tab to the 3D Viewport?
Mr batFINGER always has the good stuff, but this should get you started:
import bpy
from bpy.types import Panel


class TestPanel(Panel):
    bl_space_type = &quot;VIEW_3D&quot;
    bl_region_type = &quot;UI&quot;
    bl_label = &quot;Test Panel&quot;
    bl_category = &quot;Test Panel&quot;

    def draw(self, context):
        pass

class TestPanelSub(TestPanel, Panel):
    bl_parent_id = &quot;TestPanel&quot;
    bl_label = &quot;Test Panel Sub Panel&quot;

    def draw(self, context): 

        layout = self.layout

bpy.utils.register_class(TestPanel)
bpy.utils.register_class(TestPanelSub)