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 XML, decode, encode
class Price(Struct):
currency: Annotated[str, XML(attr=True)]
cost: Annotated[Decimal, XML(text=True)]
class Book(Struct, rename="pascal"):
title: str
prices: Annotated[list[Price], XML(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.2.1.tar.gz
(71.8 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.2.1.tar.gz.
File metadata
- Download URL: msgspec_xml-0.2.1.tar.gz
- Upload date:
- Size: 71.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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 |
ac7de60f7aaababd9f9002133c822d48fdf39331c70a9a7954f55661dc2d3120
|
|
| MD5 |
e8882a685f3de35dfcc4671f11916f58
|
|
| BLAKE2b-256 |
d48f2a3e7a673298fc7a99fb9919d522b025b312cf04b3a601dd0eeb1aac3e2e
|
File details
Details for the file msgspec_xml-0.2.1-py3-none-any.whl.
File metadata
- Download URL: msgspec_xml-0.2.1-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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 |
6356a69a00bc8c2607639053f0f2127abefc04e18a598e76817bf1548893bc8e
|
|
| MD5 |
b1eee2e7182304880acf265e96f08d84
|
|
| BLAKE2b-256 |
60044683b04371789a114283c8d89bcc02da2a546ab47475b0e43dfb36eccd10
|