Skip to main content

Converts a Python dictionary or other native data type into a valid XML string.

Project description

Supports item (int, float, bool, str, unicode, datetime, none) and collection (list, set, tuple and dict) data types with arbitrary nesting for the collections. Items with a datetime type are converted to ISO format strings. Items with a none type become empty XML elements.

The root object passed into the dicttoxml function can be any of the supported data types.

To satisfy XML syntax, the method wraps all the dict keys/elements and values in a <root> … </root> element. However, this can be disabled to create XML snippets.

For lists of items, if each item is also a collection data type (lists, dict), the elements of that item are wrapped in a generic <item> … </item> element.

Each elements includes a type attribute with the data type. Note: datetime data types are converted into ISO format strings, and unicode and datetime data types get a str attribute.

Python -> XML integer int float float string str unicode str datetime str None null boolean bool list list set list tuple list dict dict

Elements with an unsupported data type raise a TypeError exception.

Project details


Download files

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

Source Distribution

dicttoxml-1.1.2.tar.gz (3.0 kB view details)

Uploaded Source

File details

Details for the file dicttoxml-1.1.2.tar.gz.

File metadata

  • Download URL: dicttoxml-1.1.2.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for dicttoxml-1.1.2.tar.gz
Algorithm Hash digest
SHA256 69ef57e0fc6ef7cc714ec3be15804b18b3a376dd8d4e53ab0ad05c9df0c8b79c
MD5 8bb07df78d2c8249f668cb3c8638928c
BLAKE2b-256 edc9436ca7273f91e8c8bedad54f2d639f685c5b43f6b04347c38198d4b9c2be

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page