# Deleting all groups with python API

Is there a way to delete all groups with the python API? What I want to do is delete all objects and groups in the current environment and then append groups from another file. I've figured out how to delete all the objects but can't figure out how to delete the groups.

Delete all groups in blend file.

BlendDataGroups.remove(...)

import bpy

for g in bpy.data.groups:
bpy.data.groups.remove(g)


remove all empty groups (no objects assigned) from blend file

empty_groups = [g for g in bpy.data.groups if not g.objects]
while empty_groups:
bpy.data.groups.remove(empty_groups.pop())


Note: For my current version (2.79.4) there are some extra options all set to True by default to "force the issue" without having to unlink and unset users.

>>> bpy.data.groups.remove(
remove()