link collections in python

As simple as it is to link a collection with another one just by drag and drop I can't manage to find the way in python.

scene = bpy.context.scene
scene.collection.objects.link(obj)


this seem to work only with objects, how would it be with collections?

1 Answer

You need to link other collection under collection's children, not objects:

bpy.data.collections["Collection1"].children.link(bpy.data.collections["Collection2"])