How can I detect global/local view via python?
It can be done this way:

for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        space = area.spaces[0]
        if space.local_view: #check if using local view
            for region in area.regions:
                if region.type == 'WINDOW':
                    override = {'area': area, 'region': region} #override context
                    bpy.ops.view3d.localview(override) #switch to global view