msgspec-xml
XML Serialization/Deserialization using msgspec.
Installation
pdm add msgspec-xml
Usage
from decimal import Decimal
from typing import Annotated
from msgspec import Struct
from msgspec_xml import decode, encode, Attribute, Value, Wrapper
class Price(Struct):
currency: Annotated[str, Attribute()]
cost: Annotated[Decimal, Value()]
class Book(Struct, rename="pascal"):
title: str # Implied Element class
prices: Annotated[list[Price], Wrapper(wrapper="Prices", tag="Price")]
book = Book(
title="Example Book",
prices=[
Price(currency="USD", cost=Decimal("3.99")),
Price(currency="GBP", cost=Decimal("1.51")),
],
)
xml = encode(book)
# <Book>
# <Title>Example Book</Title>
# <Prices>
# <Price currency="USD">3.99</Price>
# <Price currency="GBP">1.51</Price>
# </Prices>
# </Book>
decoded = decode(xml, type_=Book)
assert decoded == book
Socials
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
msgspec_xml-0.3.1.tar.gz
(72.2 kB
view details)
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 msgspec_xml-0.3.1.tar.gz.
File metadata
- Download URL: msgspec_xml-0.3.1.tar.gz
- Upload date:
- Size: 72.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e0d9dc8a2b9553d1a21dd3e257487c34a35f523914d7e9f7713d2069ea6473c
|
|
| MD5 |
5e5b4685eac83fb8f735d9468d39099e
|
|
| BLAKE2b-256 |
4a85a3dd005092ec618d581b71a5d4961d6bbec0d0eb0f69d66c9c62d6b11230
|
File details
Details for the file msgspec_xml-0.3.1-py3-none-any.whl.
File metadata
- Download URL: msgspec_xml-0.3.1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9b75de07b2bd0ed4cd2b95e4a2eaaec835f53fff0f2e7c4b8d171264520513f
|
|
| MD5 |
dcb85fdf851b665af2321c71b655bf6d
|
|
| BLAKE2b-256 |
dff884442b0a74bec5649ba16a1269d3aff72ff1d79807accfbf548a0173d174
|