I have been looking for writing such an extension because I have to edit ~50 pdf files created with AutoCAD and each of them have ~700 imbricated groups.
Using inkscape command line works but only for a couple of imbricated groups:
$ inkscape --verb=EditSelectAll --verb=SelectionUnGroup --verb=SelectionUnGroup --verb=FileSave --verb=FileClose file.svg
This will open file.svg and ungroup as many times as there are "--verb=SelectionUnGroup" options (here two ungrouping operations). So it is ok for tens of imbricated groups but not for hundreds. Moreover it is still quite slow especially because this command line does not work with the -z option (no GUI).
Then I searched how to write a Python extension (extending default 'inkex' extension). Unfortunately I have found neither documentation about any ungrouping function nor any use of such function in an existing extension. The closest code from what I want is: http://inkscape.modevia.com/doxygen/html/perspective_8py_source.php. This site also publish the Inkscape API. It should look like:
def recursive_ungrouping (self,nodes):
for node in nodes:
if node.tag == inkex.addNS('g','svg'):
nodes_in_former_group = node.ungroup()