Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Convert XML to python Dict

Project Description

pyxml2dict is an open source python library, which used for converting xml to python dict

pyxml2dict is licensed under the GPL-3.0

Prefix the attribute in the dictionary @attribute , the value corresponding to key is #text


Install with pip:

$pip install pyxml2dict


from pyxml2dict import XML2Dict

if __name__ == '__main__':
    xml_str1 = """<root id="1"><items><item>1</item><item>2</item></items></root>"""
    xml_str2 = """<root id="1"><age>20</age><items><item id="0">1</item><item>2</item></items></root>"""
    xml2dict = XML2Dict()
    print xml2dict.fromstring(xml_str1)
    print xml2dict.fromstring(xml_str2)

print result

{'root': {'items': {'item': ['1', '2']}, '@id': '1'}}

{'root': {'items': {'item': [{'#text': '1', '@id': '0'}, '2']}, 'age': '20', '@id': '1'}}


In XML2Dict , _parse_node algorithm comes from, It’s very useful. Thanks for undefine1994.

Release History

This version
History Node


Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(3.0 kB) Copy SHA256 Hash SHA256
Source None Aug 8, 2017

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers DreamHost DreamHost Log Hosting