Set collection as Indirect Only (ie. = Shadowcatcher) through python?
You can enable Indirect Only for the currently active collection (as indicated in the outliner) by using:

bpy.context.view_layer.active_layer_collection.indirect_only = True