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.1.1.tar.gz
(70.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.1.1.tar.gz.
File metadata
- Download URL: msgspec_xml-0.1.1.tar.gz
- Upload date:
- Size: 70.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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 |
135dc23dd80b47b4f9bebfdd57ba9e79cb51daff62b84f0d44d34f848b1d0829
|
|
| MD5 |
29c6cb31f2627f892a90f781d8c7f45d
|
|
| BLAKE2b-256 |
1c165676398dee120625f244173237b5b73855f5d0eb3f9b747d18c91e9038d1
|
File details
Details for the file msgspec_xml-0.1.1-py3-none-any.whl.
File metadata
- Download URL: msgspec_xml-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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 |
07360412458375f0cb04d6695f6dc4c52550ea601751556d86244b5cfd9794e3
|
|
| MD5 |
08fb65ef87859984c6b5f131e11e7939
|
|
| BLAKE2b-256 |
238ee131ba5a2fdc4128a2564a17f2bc60c9d1e8438482b4470a77a02820a7f6
|