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.2.0.tar.gz (150.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.2.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

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

Hashes for msgspec_xml-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3dbbc170e047a26392af084337163edd16b6446babc7bf87df455d9d07c88146
MD5 493b04f358243020078cbc0e105b5c73
BLAKE2b-256 dc88ab6fb2dd2d8263b55f5e15ce6b22c44a491e25e8ba0a2b000c327fe417c4

See more details on using hashes here.

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

Hashes for msgspec_xml-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0d1684341df17fe7497a81f4d4ff07162fb6e17e2897b89353a25bf0acbb4fc4
MD5 30f2dea5f32cfe8c677e11f3f9000329
BLAKE2b-256 b1266701d07f4bd0bcf047e72402fbb5052848cd0805e916393abc4663da4468

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