Here are 2 different python functions I have made working on the Root and Ivy script. I think they could be helpful in various maya scripting cases (especially the first one). They are based on openmaya library, so they are compact and optimized.
Get closest vertex
This functions allows you to find the closest vertex on a mesh relative to a point in space. Actually, it’s similar to this code, but up-to-date and without the pymel library. The script uses openmaya getClosestPoint() to find the closest face, and look for the closest vertext constituting that face. Doing so, it avoids looping through all the vertices. The counterpart is that it won’t find any vertex that is not on the closest face so the fonction might not work on some unusual geometry.
Get curve normal and tangent
This function returns normal, tangent, and point at the closest point on a curve, given the curve and a position in space. Note that the returned list [normal, tangent, point on curve] uses the openmaya mVector class.