I have an xml I am parsing, making some changes and saving out to a new file. It has the declaration
etree.tostring(tree, pretty_print = True, xml_declaration = True, encoding='UTF-8')
Will add the declaration if you're using lxml, however I noticed their declaration uses semi-quotes instead of full quotes.
You can also get the exact declaration you want by just concatenating the output with a static string you need:
xml = etree.tostring(tree, pretty_print = True, encoding='UTF-8')
xml = '\n' + xml