Registry / serialization / dict2xml

dict2xml

JSON →
library1.7.8pypypi✓ verified 35d ago

dict2xml is a small Python utility designed to convert a Python dictionary into an XML string. It is actively maintained, with frequent minor releases. The current version is 1.7.8.

serialization
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

The primary function to convert a dictionary to XML.

from dict2xml import dict2xml

This quickstart demonstrates how to convert a nested Python dictionary into an XML string using the `dict2xml` function. It uses the `wrap` parameter to specify a root element and `indent` for readability.

from dict2xml import dict2xml data = { 'root_element': { 'item1': 123, 'item2': [ {'sub_item_a': 'hello'}, {'sub_item_b': 'world'} ], 'item3': { 'nested_value': 'example' } } } xml_string = dict2xml(data, wrap='root', indent=' ') print(xml_string)
Debug
Known footguns
gotchaThe library does not support adding attributes directly to XML elements. Dictionary keys are treated as element names, and their values as element content.
gotchaBy default, `dict2xml` sorts dictionary keys alphabetically when converting them to XML elements, which can lead to unexpected ordering if not explicitly handled. `OrderedDict` keys are *not* sorted by default.
breakingAs of version 1.7.0, `dict2xml` officially dropped support for Python 2. It is now only supported for Python 3.6+ (though it may still work in 3.5).
gotchaThe library does not automatically include an XML declaration line (e.g., `<?xml version="1.0" encoding="UTF-8"?>`) in the generated XML string.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources