Registry / devops / dicttoxml2

dicttoxml2

JSON →
library2.1.0pypypi✓ verified 86d ago

Converts a Python dictionary or other native data type into a valid XML string. Version 2.1.0 supports Python 3.7+. Active development with infrequent releases.

pip install dicttoxml2
INSTALL
IMPORT
SIG · DICTTOXML2
D
dicttoxml2
devopspythonv2.1.0
harness data pending
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.

dicttoxml
from dicttoxml2 import dicttoxml
from dicttoxml import dicttoxml
dicttoxml2 is a fork; the original dicttoxml package exists under a different name.

Convert a dict to XML bytes; set attr_type=False to omit type attributes.

from dicttoxml2 import dicttoxml data = {'name': 'Alice', 'age': 30} xml_bytes = dicttoxml(data, custom_root='person', attr_type=False) print(xml_bytes.decode('utf-8'))
Debug
Known issues
gotchaThe function returns bytes, not a string. You must decode it for a text result.
fix
Use .decode('utf-8') on the result.
affects: >=2.0.0
gotchaBy default, attr_type=True adds type attributes (e.g., type="str") to XML elements. This is often unwanted.
fix
Pass attr_type=False to suppress type annotations.
affects: all
gotchaLists without a parent key cause duplicate root elements; the function wraps each item in a <item> tag by default.
fix
Either wrap list in a dict with a root key, or use custom_root to define a root element name.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'dicttoxml'
Installed the fork dicttoxml2 but tried to import from dicttoxml.
fix
Install and import from dicttoxml2: pip install dicttoxml2 and from dicttoxml2 import dicttoxml
TypeError: a bytes-like object is required, not 'str'
Used decode on a string or passed bytes to a library that expects string.
fix
Ensure you decode the XML bytes before passing to string-only functions: xml_string = dicttoxml(data).decode('utf-8')
ValueError: Invalid root element name: ...
custom_root parameter contains characters invalid in XML (e.g., spaces, numbers at start).
fix
Use a valid XML element name: start with letter or underscore, no spaces.
Upgrade
Version history
2.1.0latest on PyPI · released Aug 13, 2022
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
dicttoxml2 — pip install dicttoxml2 · libregistry