XML Serialization/Deserialization using msgspec
Project description
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
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
msgspec_xml-0.2.0.tar.gz
(150.9 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.0.tar.gz.
File metadata
- Download URL: msgspec_xml-0.2.0.tar.gz
- Upload date:
- Size: 150.9 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 |
3dbbc170e047a26392af084337163edd16b6446babc7bf87df455d9d07c88146
|
|
| MD5 |
493b04f358243020078cbc0e105b5c73
|
|
| BLAKE2b-256 |
dc88ab6fb2dd2d8263b55f5e15ce6b22c44a491e25e8ba0a2b000c327fe417c4
|
File details
Details for the file msgspec_xml-0.2.0-py3-none-any.whl.
File metadata
- Download URL: msgspec_xml-0.2.0-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 |
0d1684341df17fe7497a81f4d4ff07162fb6e17e2897b89353a25bf0acbb4fc4
|
|
| MD5 |
30f2dea5f32cfe8c677e11f3f9000329
|
|
| BLAKE2b-256 |
b1266701d07f4bd0bcf047e72402fbb5052848cd0805e916393abc4663da4468
|