Skip to main content

XML Serialization/Deserialization using msgspec

Project description

msgspec-xml

PyPI - Python PyPI - Status PyPI - Version PyPI - License

prek Ruff ty

status-badge

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

Social - Matrix

Project details


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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

msgspec_xml-0.1.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

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

Hashes for msgspec_xml-0.1.1.tar.gz
Algorithm Hash digest
SHA256 135dc23dd80b47b4f9bebfdd57ba9e79cb51daff62b84f0d44d34f848b1d0829
MD5 29c6cb31f2627f892a90f781d8c7f45d
BLAKE2b-256 1c165676398dee120625f244173237b5b73855f5d0eb3f9b747d18c91e9038d1

See more details on using hashes here.

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

Hashes for msgspec_xml-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 07360412458375f0cb04d6695f6dc4c52550ea601751556d86244b5cfd9794e3
MD5 08fb65ef87859984c6b5f131e11e7939
BLAKE2b-256 238ee131ba5a2fdc4128a2564a17f2bc60c9d1e8438482b4470a77a02820a7f6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page