import xml.etree.ElementTree as ET my_namespaces = dict([node for _, node in ET.iterparse('file.xml', events=['start-ns'])])