Currently you cannot add namespaces to XML documents directly as it is not yet supported in the in built Python xml package. So you will need to add namespace as a normal attribute to the tag. For example,
import xml.dom.minidom
doc = xml.dom.minidom.Document()
element = doc.createElementNS('https://hello.world/ns', 'ex:el')
element.setAttribute("xmlns:ex", "https://hello.world/ns")
doc.appendChild(element)
print(doc.toprettyxml())This will give you the document,
<?xml version="1.0" ?> <ex:el xmlns:ex="https://example.net/ns"/>