How to split mesh geometry to correspond to UV islands?

I am trying to write a script to split a UV unwrapped mesh into separate pieces, such that each piece corresponds to one UV ‘island’.

It seems that many of the existing exporters do this, but looking through them I do not understand which lines of code actually do it. Can anyone point me in the right direction on this?