Closest Vertex/Edge

I’m looking for a script that allows me to snap vertices to an underlying mesh (which is selected before). I know the snapping options, but this process should be automated. Select Vertices -> Run function -> snapping is done.

Alternatively I would like to write the script myself. Does Blender have a “Closest Edge/Closest Vertex” function in the Python API?

This script should be used to retopo HardSurface/CAD data faster.
It is important to snap to certain design edges in order to be able to transfer the normals of the CAD geometry later.

Look at https://docs.blender.org/api/current/mathutils.kdtree.html

Thx!
Seems like just what I was looking for.