Python macro to sort headings

I’ve searched high and low but I cannot find an answer, much less an example of whether it can be done or not.
Would like to sort the headings alphabetically and save the doc. Is it even possible?