Skip to content
Converts XML to Python objects
Python XSLT Makefile Shell
Find file
Latest commit 5902bcc Jan 12, 2016 Christian Stefanescu Fixed line length

README.md

untangle

Build Status Code Quality Coverage Status PyPi version PyPi downloads

Join the chat at https://gitter.im/stchris/untangle

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 2.4-3.2 and pypy

Installation

pip install untangle

OR

try the latest .deb

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

1.1.0

  • dir support for untangled objects
  • code cleanups

1.0.0

  • first official release
Something went wrong with that request. Please try again.