Has anyone compiled a KDtree as plugin inside maya to find the nearest neighbor?

Being a non-api/python artist, would like to ask folks around in this forum for a help here.
A friend of mine pointed me to a python script nearpy.io but it wont work straight out of in maya.

What I am looking after is to establish a connection within max distance ( for e.g creating a curve or a particle trail between two points/particles ) when they get close to each other.
I wonder if this might need a nearest neigbor particle search on every frame & once it reaches in the min distance zone …it creates a connection !
Not sure how easy is this but any headsup or insight would be great !
Thanks,
Vik