I marked by arrows, each vertex normal, and middle arrow is just average of both vertices.
But middle arrow do not match pivot orientation (it is set to normal). Do you know how pivot calculates its orientation when multiple vertices are selected (as mentioned above it is not just average of vertices normals)? What I really want to get is pivot Z axis orientation (vector). Any ideas?

I fixed it by ‘hack’. What I did was:
calculate vector from Vert1-vert2
perpendicularVec = Vect(V1-V2).cross(oldNormal) #if you reference image above it will give vector pointing out of monitor
newNormal = perpendicularVec .cross( Vect(V1-V2)) # this reverts above line, but now NewNormal is aligned to pivot Z axis.

Not beautiful but it works. It would be interesting anyway, how, where do I get gizmo data (loc, rot, scale) ?
And what it was for- trim based on selection:

Custom transform orientations got a .matrix property, but built-in orientations do not expose something like that. You could add a transform orientation and read the matrix to get the orientation of the built-in local. But for all other types, own code is required to calculate the matrices.