Skip to content

stchris/untangle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

7eec044 · Jan 19, 2024
Jan 3, 2023
Jul 1, 2022
Jul 2, 2022
Jul 1, 2022
Jul 20, 2016
Jul 1, 2020
Jul 2, 2022
Jun 5, 2011
Jul 2, 2022
Jul 1, 2022
Jul 1, 2022
Nov 13, 2019
Jul 2, 2022
Jul 2, 2022
Jul 2, 2022
Jan 18, 2024
Jul 1, 2022

Repository files navigation

untangle

Build Status PyPi version Code style: black

Documentation

  • Converts XML to a Python object.
  • Siblings with similar names are grouped into a list.
  • Children can be accessed with parent.child, attributes with element['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 with foobar.foo_bar, <foo.bar.baz/> can be accessed with foo_bar_baz and <foo:bar><foo:baz/></foo:bar> can be accessed with foo_bar.foo_baz
  • Works with Python 3.7 - 3.10

Installation

With pip:

pip install untangle

With conda:

conda install -c conda-forge untangle

Conda feedstock maintained by @htenkanen. Issues and questions about conda-forge packaging / installation can be done here.

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
  • 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'

Changelog

see CHANGELOG.md