lxml has been mentioned. You might also check out lxml.objectify for some really simple manipulation.

>>> from lxml import objectify
>>> tree = objectify.fromstring(your_xml)
>>> tree.weather.attrib["module_id"]
'0'
>>> tree.weather.forecast_information.city.attrib["data"]
'Mountain View, CA'
>>> tree.weather.forecast_information.postal_code.attrib["data"]
'94043'
Answer from Ryan Ginstrom on Stack Overflow
🌐
Python
docs.python.org › 3 › library › xml.html
XML Processing Modules — Python 3.14.3 documentation
Source code: Lib/xml/ Python’s interfaces for processing XML are grouped in the xml package. It is important to note that modules in the xml package require that there be at least one SAX-compliant...
🌐
Python
docs.python.org › 3 › library › xml.etree.elementtree.html
xml.etree.ElementTree — The ElementTree XML API
January 29, 2026 - Source code: Lib/xml/etree/ElementTree.py The xml.etree.ElementTree module implements a simple and efficient API for parsing and creating XML data. Tutorial: This is a short tutorial for using xml....
Discussions

Really simple way to deal with XML in Python? - Stack Overflow
See also the reference to the PicklingTools libraries in the answer at stackoverflow.com/a/7531652/507544 - that allows you to map forward and back between XML and Python dictionaries, with various options for handling the complexities that arise. More on stackoverflow.com
🌐 stackoverflow.com
beautifulsoup - For web scraping and xml parsing, which is best library to learn - Stack Overflow
Beautiful Soup is library for parsing/pulling data from XML and HTML files. xml.elementtree provides object representation of the XML file and it is a XML processing module of Python XML package. More on stackoverflow.com
🌐 stackoverflow.com
XML Processing in Python - Stack Overflow
If you can conceivably write the ... special library to write it. If the document is too complicated to write by hand, then you should probably look into one of the frameworks already mentioned. At no point should you need to write a general XML writer. ... You can also try untangle to parse simple XML documents. ... Since you mentioned that you'll be building "fairly simple" XML, the minidom module (part of the Python Standard Library) ... More on stackoverflow.com
🌐 stackoverflow.com
Python Manipulate and save XML without third-party libraries - Stack Overflow
I have a xml in which I have to search for a tag and replace the value of tag with a new values. For example, oldName and replace oldName to newName like ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Real Python
realpython.com › python-xml-parser
A Roadmap to XML Parsers in Python – Real Python
September 25, 2023 - If you’ve ever tried to parse an XML document in Python before, then you know how surprisingly difficult such a task can be. On the one hand, the Zen of Python promises only one obvious way to achieve your goal. At the same time, the standard library follows the batteries included motto by letting you choose from not one but several XML parsers.
🌐
GeeksforGeeks
geeksforgeeks.org › python › xml-parsing-python
XML parsing in Python - GeeksforGeeks
June 28, 2022 - Our goal is to process this RSS feed (or XML file) and save it in some other format for future use. Python Module used: This article will focus on using inbuilt xml module in python for parsing XML and the main focus will be on the ElementTree XML API of this module.
🌐
The Hitchhiker's Guide to Python
docs.python-guide.org › scenarios › xml
XML parsing — The Hitchhiker's Guide to Python
untangle is a simple library which takes an XML document and returns a Python object which mirrors the nodes and attributes in its structure.
Find elsewhere
🌐
lxml
lxml.de
lxml - Processing XML and HTML with Python
lxml - the most feature-rich and easy-to-use library for processing XML and HTML in the Python language
🌐
PyPI
pypi.org › project › xml-python
xml-python
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
Top answer
1 of 9
19

lxml has been mentioned. You might also check out lxml.objectify for some really simple manipulation.

>>> from lxml import objectify
>>> tree = objectify.fromstring(your_xml)
>>> tree.weather.attrib["module_id"]
'0'
>>> tree.weather.forecast_information.city.attrib["data"]
'Mountain View, CA'
>>> tree.weather.forecast_information.postal_code.attrib["data"]
'94043'
2 of 9
10

You want a thin veneer? That's easy to cook up. Try the following trivial wrapper around ElementTree as a start:

# geetree.py
import xml.etree.ElementTree as ET

class GeeElem(object):
    """Wrapper around an ElementTree element. a['foo'] gets the
       attribute foo, a.foo gets the first subelement foo."""
    def __init__(self, elem):
        self.etElem = elem

    def __getitem__(self, name):
        res = self._getattr(name)
        if res is None:
            raise AttributeError, "No attribute named '%s'" % name
        return res

    def __getattr__(self, name):
        res = self._getelem(name)
        if res is None:
            raise IndexError, "No element named '%s'" % name
        return res

    def _getelem(self, name):
        res = self.etElem.find(name)
        if res is None:
            return None
        return GeeElem(res)

    def _getattr(self, name):
        return self.etElem.get(name)

class GeeTree(object):
    "Wrapper around an ElementTree."
    def __init__(self, fname):
        self.doc = ET.parse(fname)

    def __getattr__(self, name):
        if self.doc.getroot().tag != name:
            raise IndexError, "No element named '%s'" % name
        return GeeElem(self.doc.getroot())

    def getroot(self):
        return self.doc.getroot()

You invoke it so:

>>> import geetree
>>> t = geetree.GeeTree('foo.xml')
>>> t.xml_api_reply.weather.forecast_information.city['data']
'Mountain View, CA'
>>> t.xml_api_reply.weather.current_conditions.temp_f['data']
'68'
🌐
Python
wiki.python.org › moin › PythonXml
PythonXml
a pythonesque, simple-to-use and very fast XML tree library:
🌐
ScrapingAnt
scrapingant.com › blog › python-parse-xml
How to Parse XML in Python | ScrapingAnt
August 2, 2024 - These built-in Python XML parsers offer a good balance of speed and ease of use for most applications. ... Consider using lxml, a fast and feature-rich Python library that combines the power of libxml2 and libxslt (lxml documentation).
🌐
GitHub
github.com › oxylabs › how-to-parse-xml-in-python
GitHub - oxylabs/how-to-parse-xml-in-python: Follow this in-depth technical tutorial to learn how to parse XML data in Python, what libraries you should use, how to handle invalid XML, and more. · GitHub
The ElementTree API is a lightweight, feature-rich Interface for parsing and manipulating XML documents. The implementation is fast and elegant which attracted many third-party libraries to build on it. The documentation of this library is also better than minidom. When it was first introduced in Python 2.5, it had a faster C implementation named cElementTree.
Author   oxylabs
🌐
PyPI
pypi.org › project › xmlschema
xmlschema · PyPI
The xmlschema library is an implementation of XML Schema for Python.
      » pip install xmlschema
    
Published   Jan 17, 2026
Version   4.3.1
🌐
DataCamp
datacamp.com › tutorial › python-xml-elementtree
Python XML Tutorial: Element Tree Parse & Read | DataCamp
December 10, 2024 - The XML tree structure makes navigation, modification, and removal relatively simple programmatically. Python has a built-in library, ElementTree, that has functions to read and manipulate XMLs (and other similarly structured files).
🌐
Real Python
realpython.com › ref › stdlib › xml
xml | Python Standard Library – Real Python
The Python xml package provides tools for parsing and creating XML documents that you can use to store and transport structured data.
🌐
Nick Janetakis
nickjanetakis.com › blog › how-i-used-the-lxml-library-to-parse-xml-20x-faster-in-python
How I Used the lxml Library to Parse XML 20x Faster in Python — Nick Janetakis
August 20, 2019 - One of the reasons why lxml is so fast is because it uses that package’s C code to do most of the heavy lifting for parsing XML. The 2 Python libraries we’re installing are pip install xmltodict==0.12.0 lxml==4.4.1.
🌐
Apify
blog.apify.com › python-parse-xml
How to parse XML in Python
July 16, 2025 - LXML is the most feature-rich and easy-to-use library for processing XML and HTML in the Python language.