getting mask data into shader network through python or any other way
I don't think there is a direct way to do this; Blender only has a Mask node in the render layer compositor, and not in the material compositor.