Create a template configured to trace a subnetwork, remove containers, and loop on a set of reduction rules. The rules will reduce all system and miscellaneous junctions that are connected to 0, 1, or 2 other junctions, reduce all distribution devices except circuit breakers and switches that are connected to 0, 1, or 2 other junctions, and reduce all system and miscellaneous junctions that are connected to 3 or more other junctions.
import arcpy
input_Network = "D:/MyProjectLocation/MyDatabaseConnection.sde/MyDatabase.MAP.Electric/MyDatabase.MAP.Electric"
input_DiagramTemplate = "Template1"
input_StructureJunction = "D:/MyProjectLocation/MyDatabaseConnection.sde/MyDatabase.MAP.Electric/MyDatabase.MAP.StructureJunction"
input_DistributionAssembly = "D:/MyProjectLocation/MyDatabaseConnection.sde/MyDatabase.MAP.Electric/MyDatabase.MAP.ElectricDistributionAssembly"
input_DistributionDevice = "D:/MyProjectLocation/MyDatabaseConnection.sde/MyDatabase.MAP.Electric/MyDatabase.MAP.ElectricDistributionDevice"
input_MiscJunction = "D:/MyProjectLocation/MyDatabaseConnection.sde/MyDatabase.MAP.Electric/MyDatabase.MAP.ElectricDistributionJunction"
input_SystemJunctions = "D:/MyProjectLocation/MyDatabaseConnection.sde/MyDatabase.MAP.Electric/MyDatabase.MAP.UN_112_SystemJunctions"
arcpy.nd.AddDiagramTemplate(input_Network, input_DiagramTemplate)
arcpy.nd.AddTraceRule(input_Network, input_DiagramTemplate, "ACTIVE", 
                      "SUBNETWORK", "ElectricDistribution", "Medium Voltage", 
                      "Low Voltage Mesh")
arcpy.nd.AddRemoveFeatureRule(input_Network, input_DiagramTemplate, 
                              'ACTIVE', 'INCLUDE_SOURCE_CLASSES', 
                              input_StructureJunction + ";" + input_DistributionAssembly)
arcpy.nd.AddStartIterationRule(input_Network, input_DiagramTemplate, 
                               'ACTIVE')
arcpy.nd.AddReduceJunctionRule(input_Network, input_DiagramTemplate, 
                               'ACTIVE', 'INCLUDE_SOURCE_CLASSES', 
                               input_SystemJunctions + ";" + input_MiscJunction, 
                               "MAX_2_CONNECTED_JUNCTIONS", 
                               "REDUCE_UNCONNECTED_JCT", 
                               "REDUCE_JCT_TO_1JCT", "REDUCE_JCT_TO_2JCTS")
arcpy.nd.AddReduceJunctionByAttributesRule(input_Network, 
                                           input_DiagramTemplate, 'ACTIVE', "", 
                                           input_DistributionDevice, 
                                           "ASSETGROUP NOT IN (4, 15)", 
                                           "MAX_2_CONNECTED_JUNCTIONS", 
                                           "REDUCE_UNCONNECTED_JCT", 
                                           "REDUCE_JCT_TO_1JCT", 
                                           "REDUCE_JCT_TO_2JCTS")
arcpy.nd.AddReduceJunctionRule(input_Network, input_DiagramTemplate, 
                               'ACTIVE', 'INCLUDE_SOURCE_CLASSES', 
                               input_SystemJunctions + ";" + input_MiscJunction, 
                               "MIN_3_CONNECTED_JUNCTIONS")
arcpy.nd.AddStopIterationRule(input_Network, input_DiagramTemplate, 
                              'ACTIVE')