ID Mask by Pass Index in bpy New to Blender, and the documentation for bpy is throwing me for a few loops. I got a setup in the compositing layer working for my desired goal as shown:

This renders an image and a color-coded mask for each of the three unique pass_index marked objects (below), and am trying to automate this through a bpy script as there are many variations I'll need to render.

Each object can be given a pass index in bpy via e.g. bpy.data.objects['foo'].pass_index = bar, but I'm having trouble figuring out how to separate each layer(?) via pass index as the compositing nodes do. Simple camera manipulations and the like are straightforward (I have a script that can import the stl, setup camera/lighting as required, and produce images like the left one above), but I'm lacking the terminology to search the right question or understand the documentation- and recent changes between 2.7x and 2.8x make a number of older guides very difficult to understand...
Related would be the steps of adding a color and recombining to form a single image as shown in the compositing layer, but small steps first. Any help would be appreciated, thank you!
Specific answer for the task at hand (image segmentation) is given by the bpycv module. This isn't the same as a general compositor -&gt; bpy solution, but posting here in case someone else also happens to (somehow) miss bpycv, yet find this post.