How to render surface Normal maps in Blender?

I wonder how I can render camera-view invariant surface Normal maps in Blender (or better, through Blender’s Python API)? Maybe as the first step, can someone explain how one can obtain surface Normals? My goal is actually to get surface Normal maps that are not dependent on the camera angle. How can I do that?
Currently, I can only see the surface Normal maps by pressing N on the keyboard and then clicking on Matcap and selecting the Normal ball as shown below. But first I do not know how to render this, and second I do not know how to make it camera-view invariant.

Okay I don’t know exactly what invariant means or exactly what you are fully trying to say but here goes. After some initial google-duckduckgo-fu I came accross this webpage
. So I tried and came up with this.

All you have to do is apply that material to your object and you can render it in cycles. I have not tested baking but I suspect you could bake the texture but I am not sure if it is view angle independent. However it looks exactly how it does in normal matcap view for normals. It may not work for the other mat-caps and may need adjusting. That’s all I can do. Good luck and I hope it helps.

Also you do not need to uv-unwrap your item for this to work the only texture it is using at the moment is the matcap I packed into the blendfile.

I found the answer to my question here: