untangle

by stchris

stchris / untangle

Converts XML to Python objects

474 Stars 67 Forks Last release: over 6 years ago (1.1.0) MIT License 195 Commits 7 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

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
    _
     can be accessed with 
    foobar.foo_bar
    ,
     can be accessed with 
    foo_bar_baz
    and
     can be accessed with 
    foo_bar.foo_baz
  • Works with Python 2.7 and 3.4, 3.5, 3.6, 3.7, 3.8 and pypy

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:

    

allows it to be navigated from the

untangle
d object like this:
obj.root.child['name'] # u'child1'

Changelog

see CHANGELOG.md

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.