# How can I remove a linked library with Python?

I'm working on an add-on. The purpose is to link and un-link groups from another blend file. Thanks to stack exchange and the Blender documentation this works pretty well.

This means I can load a library and import a group from it.

with bpy.data.libraries.load(path, link=True) as (sourceData, targetData):
targetData.groups = sourceData.groups


Then I search the library and extract the group to create an instance of the group:

instance = bpy.data.objects.new(name, None)
instance.dupli_type = 'GROUP'
instance.dupli_group = group


The result is a dupli-group object that links in the other blend file. (the link is persistent and will survive a reload .. that is what I want).

My idea is to do the opposite. If the user does not want this link anymore, I would like to get rid of

• the instance
• the group

This works pretty nicely too for this instance:

context.scene.objects.unlink(instance)
bpy.data.objects.remove(instance)


and the group:

group.user_clear()
bpy.data.groups.remove(group)


I saw (in the outliner/Blendfile)there is still a user to the library. I guess it is the group object. So I removed that too:

for object in  library.users_id:
for object in  library.users_id:
object.user_clear()
bpy.data.objects.remove(object)


Now the outline shows me the library without any user ... but

It seems there is no API call to do that. bpy.data.libraries.remove() does not exist. There is a load but no unload.

Saving/Loading the file removes the library. But this is far away from any comfort.

Reloading the blend file destroys the current context. E.g. undo would not be possible anymore. It also involves unnecessary file operations, that leads to another cycle in the backup files. Beside of that it simply feels incorrect to use such a workaround (Imagine you need to restart your PC each time you delete a file)

I found this one: Q: Proper way to remove unused linked Group data-blocks but this does not answer my question as I want to get rid of the library not just the group.

Do I miss something?

Thank you Monster

• Great question! Would be awesome to have this as add-on. Major issue is removing the group IMO, unfortunately I also could not find a proper way of doing this. Why not starting a bounty to get more attention? – p2or Jan 15 '16 at 10:49
• I really think this is not implemented. I doubt a bounty will help there any further. – Monster Jan 15 '16 at 19:53