# How to get the collection an object belongs to?

I can access objects belonging to a collection like so:

objects_in_collection = bpy.data.collections["My_Collection"].objects


How can I access the collection a specific object belongs to?

## 2 Answers

Object.users_collection property returns a tuple containing all linked collections:

>>> obj = bpy.context.object
>>> obj.users_collection
(bpy.data.collections['Collection'],)

• Many thanks! I also needed to get the name of the collection and was able to do so like this: ob.users_collection[0].name Mar 21 '19 at 14:59
• @brockmann :: Is the result always by order? e.g. [0] = direct parent? The official document in your link lacks detail. Jul 18 '20 at 4:10
• Not sure, just test it. If not the case, you can sort it: blender.stackexchange.com/questions/146685/… @cppBeginner Jul 18 '20 at 18:16
• This doesn't seem to work in drivers. Apr 18 at 22:26

Select this object by name and it should take you to the right collection. Selection by name is described in this section.