Rendering multi-layer EXR using File Output node in Python I'm writing a multi-view synthetic dataset generator and I want to save my rendered images as multi-layer EXR. I have a basic Python script that loads a template file with the compositing nodes below, append an object and renders from different views by varying the camera position.
When I render a scene in Blender, I get the desired result: a multi-layer EXR image with denoised colors, raw normals and clipped depths. However, I cannot find a way to render to the File Output node in Python, since scene.render.filepath is different than nodes['File Output'].base_path. When I call bpy.ops.render.render(write_still=True), I get a multi-layer EXR that essentially ignores my output node and just uses the value in Output Properties. This is true even if I remove the denoising node.
Is there any way to render through the File Output node in Python? Is my Composite node actually correct? I need compositing because I want to use the denoiser to reduce render times. Both scene.use_nodes and scene.render.use_compositing are set to True in my code.
In order to change the path of the output node you would have to set OutputNode.base_path. Make sure RenderSettings.use_compositing as well as Scene.use_nodes is enabled. Tested against the following node setup successfully:

import bpy, os

C = bpy.context

# Enable Post Processing and Use Nodes
C.scene.render.use_compositing = True
C.scene.use_nodes = True

# Get the File Output Node by name
out = C.scene.node_tree.nodes.get(&quot;File Output&quot;)

if out:
    # Set the output path of the node based 
    # on the regular path of the output
    out_dir = os.path.dirname(C.scene.render.filepath)
    out.base_path = os.path.join(out_dir, &quot;multilayer_&quot;)
    # Call the render operator
    bpy.ops.render.render(write_still=True)

Related: How to properly connect the Denoise node in Compositor?

Rendering in headless mode works as well:
./Blender -b file.blend -P script.py


Layer Contact Sheet node in Natron