Converts XML to Python objects
Project Links
Meta
Author: Christian Stefanescu
Requires Python: >=3.10
Classifiers
untangle
- Converts XML to a Python object.
- Siblings with similar names are grouped into a list.
- Children can be accessed with
parent.child, attributes withelement['attribute']. - You can call the
parse()method with a filename, an URL or an XML string. - Substitutes
-,.and:with_<foobar><foo-bar/></foobar>can be accessed withfoobar.foo_bar,<foo.bar.baz/>can be accessed withfoo_bar_bazand<foo:bar><foo:baz/></foo:bar>can be accessed withfoo_bar.foo_baz
Installation
With pip:
pip install untangle
Usage
(See and run examples.py or this blog post: Read XML painlessly for more info)
import untangle
obj = untangle.parse(resource)
resource can be:
- a URL
- a filename (a string or an
os.PathLikeobject such aspathlib.Path) - an XML string
Running the above code and passing this XML:
<?xml version="1.0"?>
<root>
<child name="child1"/>
</root>
allows it to be navigated from the untangled object like this:
obj.root.child["name"] # u'child1'
Development
untangle uses uv for builds and virtualenv management:
$ uv sync
Run tests:
$ uv run pytest
Run linter:
$ uv run ruff check .
Run formatter checks:
$ uv run ruff format --check
Run type hint checks:
$ uv run ty check .
Changelog
see CHANGELOG.md
1.3.0
Sep 23, 2026
1.2.1
Jul 02, 2022
1.2.0
Jul 01, 2022
1.1.1
May 07, 2017
1.1.0
Dec 17, 2012
1.0.0
Apr 23, 2012
0.4.0
Feb 28, 2012
0.3.1
Jun 13, 2011
0.3
Jun 08, 2011
Wheel compatibility matrix
Files in release
Extras:
None
Dependencies:
defusedxml
(==0.7.1)