How can I calculate the pixel size for each direction of my rendered image?
Here is an illustrative code fragment to show how to compute the pixel sizes in each direction (u is horizontal, v is vertical):

scale = scene.render.resolution_percentage / 100
pixels_in_u_per_mm = resolution_x_in_px * scale / sensor_width_in_mm
pixels_in_v_per_mm = resolution_y_in_px * scale * aspect_ratio / sensor_height_in_mm
pixel_size_in_u_direction = 1/pixels_in_u_per_mm
pixel_size_in_v_direction = 1/pixels_in_v_per_mm


By experimenting with blender, I found out that by default (camera sensor fit set to "auto") the sensor width is fixed, the sensor height is effectively changed with the aspect ratio settings.

The current Blender GUI only specifies the sensor width by default, but there is a variable for sensor height in the internal camera data. It is used if the camera's sensor fit is set to something other than "Auto", which I don't currently cover in this answer (see next paragraph for another answer where I cover these).

The above code is based on the Python code in my answer to What is blender&#39;s camera projection matrix model?. You can find details on how to get the relevant parameters there, and also how to deal with other sensor fit settings.