Simple, fast, lightweight xml parser and validator defined by classes.
Project description
XML Classes
Simple, fast, lightweight xml parser and validator defined by classes, and useful error messages.
Reason to pick this over other xml parsers:
- Non alias. (Harder to match tag/attribute name with the class variable name)
- Need advanced features. (Like default factory, custom decoder, custom encoder etc.)
TODO: Speed test against pydantic-xml and xmltodict with pydantic.
Basic examples:
For the following XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<root value="data" />
The following python class can be used to parse it:
class RootAttribute(XmlClass):
value: str
It automatically assumes it is an xml tag attribute.
And then parse it:
root = RootAttribute.from_string(xml_string)
For the following XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<root>
<value value="data"/>
</root>
The following python class can be used to parse it:
class Value(XmlClass):
value: str
class RootElement(XmlClass):
value: Value
When the type is set to be of XmlClass, it will be parsed as a sub element.
For xml text field, it is a bit more complex. For the following XML: """
data1 """The following python class can be used to parse it:
class Value(XmlClass):
data: XmlTextField[str]
When the type is set to be of XmlTextField, it will be parsed as a text field, where the text-field is of the type given in the square brackets.
Supported Annotations type:
- int
- float
- str
- bool [^4]
- None
- datetime.datetime [^2]
- uuid.UUID
- pathlib.Path
- typing.Any [^3]
- Literal
- Enum
- list [^1]
- tuple [^1]
- union
- XmlClass
- XmlTextField
[^1]: Assume that the children can only be of type: XmlClass.
Since multiple attributes are not allowed, and a data separator
is not defined.
[^2]: Is parsed by the datetime.datetime.fromisoformat method.
[^3]: Is parsed as is (as string). Only check if there is data.
[^4]: Where ["true", "1", "yes", "on"] is true and ["false", "0", "no", "off"] is false.
NOTE:
- This is a work in progress, ATM it only parses the XML data, to a python class.
- UNSURE: Do None type hint as the only one even make sense?
TODO:
- Make a test for typing.Any.
- Added
defusedxmlas dependency. (Security reasons) - Fix ALL type hints...
- Add support for decoder and encoder.
- Add support for custom parsers. (XmlDataParser[MyParserOfData])
- Make good and useful error messages.
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 xmlclasses-0.1.1.tar.gz.
File metadata
- Download URL: xmlclasses-0.1.1.tar.gz
- Upload date:
- Size: 27.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c57766b6467648533e6482985c91440ea30d44af64528ecea879937b6980749
|
|
| MD5 |
ca3ff543d28885a4877ee4e60e364450
|
|
| BLAKE2b-256 |
574d8f4c6106f3aaf78f8ac2b6c6f893fce448722b80e96782f2d260f7cd6e3f
|
Provenance
The following attestation bundles were made for xmlclasses-0.1.1.tar.gz:
Publisher:
python-publish.yml on tacozMacleo/xmlClasses
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xmlclasses-0.1.1.tar.gz -
Subject digest:
9c57766b6467648533e6482985c91440ea30d44af64528ecea879937b6980749 - Sigstore transparency entry: 602210258
- Sigstore integration time:
-
Permalink:
tacozMacleo/xmlClasses@68683e312c39b49fe0bd030b5ecefece30850b1a -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/tacozMacleo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@68683e312c39b49fe0bd030b5ecefece30850b1a -
Trigger Event:
release
-
Statement type:
File details
Details for the file xmlclasses-0.1.1-py3-none-any.whl.
File metadata
- Download URL: xmlclasses-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
106b74f9fc94f389bb83e8cf2f554f0a1ebd3090b699cf6cf01117c81df68dfa
|
|
| MD5 |
edca2a09d800bffc115b90ee853aeaa2
|
|
| BLAKE2b-256 |
d1c19bfdf9a3ba8aa6b5664f60f7678429521ef3824de50c1100e7c21fa1a9f2
|
Provenance
The following attestation bundles were made for xmlclasses-0.1.1-py3-none-any.whl:
Publisher:
python-publish.yml on tacozMacleo/xmlClasses
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xmlclasses-0.1.1-py3-none-any.whl -
Subject digest:
106b74f9fc94f389bb83e8cf2f554f0a1ebd3090b699cf6cf01117c81df68dfa - Sigstore transparency entry: 602210275
- Sigstore integration time:
-
Permalink:
tacozMacleo/xmlClasses@68683e312c39b49fe0bd030b5ecefece30850b1a -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/tacozMacleo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@68683e312c39b49fe0bd030b5ecefece30850b1a -
Trigger Event:
release
-
Statement type: