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.0.tar.gz
(72.0 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.0.tar.gz.
File metadata
- Download URL: msgspec_xml-0.3.0.tar.gz
- Upload date:
- Size: 72.0 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 |
427cb8de2cd91a3e9320e7d0defa157b6a0465fe3f2b3a870cd912f1fef71f35
|
|
| MD5 |
98076b09962c37a607f50f333f4b8d12
|
|
| BLAKE2b-256 |
5c31862fe46c0b89afaade0eefdfee31ff89952306b98bdef48d95d21f7b4ce6
|
File details
Details for the file msgspec_xml-0.3.0-py3-none-any.whl.
File metadata
- Download URL: msgspec_xml-0.3.0-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 |
5758dbbfcaa3286ba85b73ed7d4cbb51a4f0a7cca479d6d14cbfb1564d41dc0c
|
|
| MD5 |
b6be564667de50c3cc80fecab8951dd4
|
|
| BLAKE2b-256 |
fff4dee7a0f3499448bff15aef66aeffafe23fdfd550cabd2cab1352359644e0
|