Skip to main content

xml to dictionary tool for python

Project description

xmlpydict 📑

XML Tests PyPI versions PyPI

Requirements

  • python 3.8+

Installation

To install xmlpydict, using pip:

pip install xmlpydict

Quickstart

>>> from xmlpydict import parse
>>> parse("<package><xmlpydict language='python'/></package>")
{'package': {'xmlpydict': {'@language': 'python'}}}
>>> parse("<person name='Matthew'>Hello!</person>")
{'person': {'@name': 'Matthew', '#text': 'Hello!'}}

Goals

Create a consistent parsing strategy between XML and Python dictionaries using the specification found here. xmlpydict focuses on speed; see the benchmarks below.

small_xml_document large_xml_document

xmlpydict supports the following

CDataSection: CDATA Sections are stored as {'#text': CData}.

Comments: Comments are tokenized for corectness, but have no effect in what is returned.

Element Tags: Allows for duplicate attributes, however only the latest defined will be taken.

Characters: Similar to CDATA text is stored as {'#text': Char} , however this text is stripped.

# Empty tags are containers
>>> from xmlpydict import parse
>>> parse("<a></a>")
{'a': None}
>>> parse("<a/>")
{'a': None}
>>> parse("<a/>").get('href')
None

Attribute prefixing

# Change prefix from default "@" with keyword argument attr_prefix
>>> from xmlpydict import parse
>>> parse('<p width="10" height="5"></p>', attr_prefix="$")
{"p": {"$width": "10", "$height": "5"}}

Exceptions

# Grammar and structure of the xml_content is checked while parsing
>>> from xmlpydict import parse
>>> parse("<a></ a>")
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 5

Unsupported

Prolog / Enforcing Document Type Definition and Element Type Declarations

Entity Referencing

Namespaces

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

xmlpydict-0.0.16.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xmlpydict-0.0.16-cp310-cp310-manylinux1_x86_64.manylinux_2_34_x86_64.manylinux_2_5_x86_64.whl (147.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64manylinux: glibc 2.5+ x86-64

File details

Details for the file xmlpydict-0.0.16.tar.gz.

File metadata

  • Download URL: xmlpydict-0.0.16.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for xmlpydict-0.0.16.tar.gz
Algorithm Hash digest
SHA256 80a0711f0111bc56385211968d4ac78dae6e787c3711175e83d9a4d9c620c65a
MD5 5b35d5d8f244fa9746bb9031ae7ff83c
BLAKE2b-256 bcb0f5f98317cbd84381c816646e31367b552e56b2de315139c10c3493e025d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for xmlpydict-0.0.16.tar.gz:

Publisher: python-publish.yml on MatthewAndreTaylor/xmlpydict

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file xmlpydict-0.0.16-cp310-cp310-manylinux1_x86_64.manylinux_2_34_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for xmlpydict-0.0.16-cp310-cp310-manylinux1_x86_64.manylinux_2_34_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 754f588be8af061f21e47a2d697dbb33bdd8d2ae229b565ad7a1e5d95e95c872
MD5 ab363f30ef3691047edfc6c2b15c0c65
BLAKE2b-256 3d346916bb48f9d94eb06cdb8bd4a1dd68ace248aa610383b670c0e3c85b00e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for xmlpydict-0.0.16-cp310-cp310-manylinux1_x86_64.manylinux_2_34_x86_64.manylinux_2_5_x86_64.whl:

Publisher: python-publish.yml on MatthewAndreTaylor/xmlpydict

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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