Skip to main content

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

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

Uploaded Python 3

File details

Details for the file msgspec_xml-0.2.1.tar.gz.

File metadata

  • Download URL: msgspec_xml-0.2.1.tar.gz
  • Upload date:
  • Size: 71.8 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.1.tar.gz
Algorithm Hash digest
SHA256 ac7de60f7aaababd9f9002133c822d48fdf39331c70a9a7954f55661dc2d3120
MD5 e8882a685f3de35dfcc4671f11916f58
BLAKE2b-256 d48f2a3e7a673298fc7a99fb9919d522b025b312cf04b3a601dd0eeb1aac3e2e

See more details on using hashes here.

File details

Details for the file msgspec_xml-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: msgspec_xml-0.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6356a69a00bc8c2607639053f0f2127abefc04e18a598e76817bf1548893bc8e
MD5 b1eee2e7182304880acf265e96f08d84
BLAKE2b-256 60044683b04371789a114283c8d89bcc02da2a546ab47475b0e43dfb36eccd10

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.1

2 files

0.3.0

2 files

This release

0.2.1 This release

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page