Edit Mode Transform Median X, Y, Z location. How to read the N-Panel
I didn't see a response but this is the code that I used:
I think the original author was CodeManX

    def calcpivotpoint(theobject):
        ob = theobject
        me = ob.data    

        bm = bmesh.from_edit_mesh(me)
        verts_sel = [v.co for v in bm.verts if v.select]

        pivot = sum(verts_sel, Vector()) / len(verts_sel)

        return ob.matrix_world @ pivot