xml to dictionary tool for python
Project description
xmlpydict 📑
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.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xmlpydict-0.0.17.tar.gz.
File metadata
- Download URL: xmlpydict-0.0.17.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41ea248060c214060b73cac40c42b9e139ca80a3c47b2ceb07fa64fc17477e29
|
|
| MD5 |
429593bbc95699e16758d186eb28c026
|
|
| BLAKE2b-256 |
77da5dd1378e9c1471a0a65ce0ab74c4da8f525653386fee5177f9a8be69e3a3
|
Provenance
The following attestation bundles were made for xmlpydict-0.0.17.tar.gz:
Publisher:
python-publish.yml on MatthewAndreTaylor/xmlpydict
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xmlpydict-0.0.17.tar.gz -
Subject digest:
41ea248060c214060b73cac40c42b9e139ca80a3c47b2ceb07fa64fc17477e29 - Sigstore transparency entry: 1051729885
- Sigstore integration time:
-
Permalink:
MatthewAndreTaylor/xmlpydict@7254b2663bd0d8a1db0aa2fbb13a5b1e5413324f -
Branch / Tag:
refs/tags/v0.0.17 - Owner: https://github.com/MatthewAndreTaylor
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@7254b2663bd0d8a1db0aa2fbb13a5b1e5413324f -
Trigger Event:
release
-
Statement type:
File details
Details for the file xmlpydict-0.0.17-cp310-cp310-manylinux1_x86_64.manylinux_2_34_x86_64.manylinux_2_5_x86_64.whl.
File metadata
- Download URL: xmlpydict-0.0.17-cp310-cp310-manylinux1_x86_64.manylinux_2_34_x86_64.manylinux_2_5_x86_64.whl
- Upload date:
- Size: 147.4 kB
- Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60cb5b689a8b71de291fd51650ccd072ca854f5caf62a76b09e3152659b7dbdb
|
|
| MD5 |
b1bc1611a92b2463222152c4ab046f63
|
|
| BLAKE2b-256 |
528ad5ccb7dd04284e5377ede5104645d549f56f89d839f8dc54bc6672211a9b
|
Provenance
The following attestation bundles were made for xmlpydict-0.0.17-cp310-cp310-manylinux1_x86_64.manylinux_2_34_x86_64.manylinux_2_5_x86_64.whl:
Publisher:
python-publish.yml on MatthewAndreTaylor/xmlpydict
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xmlpydict-0.0.17-cp310-cp310-manylinux1_x86_64.manylinux_2_34_x86_64.manylinux_2_5_x86_64.whl -
Subject digest:
60cb5b689a8b71de291fd51650ccd072ca854f5caf62a76b09e3152659b7dbdb - Sigstore transparency entry: 1051729902
- Sigstore integration time:
-
Permalink:
MatthewAndreTaylor/xmlpydict@7254b2663bd0d8a1db0aa2fbb13a5b1e5413324f -
Branch / Tag:
refs/tags/v0.0.17 - Owner: https://github.com/MatthewAndreTaylor
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@7254b2663bd0d8a1db0aa2fbb13a5b1e5413324f -
Trigger Event:
release
-
Statement type: