Create a mesh in python script

You can use the Segment Statistics module to do that. See for example