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 decode, encode, Attribute, Value, Wrapper


class Price(Struct):
    currency: Annotated[str, Attribute()]
    cost: Annotated[Decimal, Value()]


class Book(Struct, rename="pascal"):
    title: str  # Implied Element class
    prices: Annotated[list[Price], Wrapper(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.3.0.tar.gz (72.0 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.3.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: msgspec_xml-0.3.0.tar.gz
  • Upload date:
  • Size: 72.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","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.3.0.tar.gz
Algorithm Hash digest
SHA256 427cb8de2cd91a3e9320e7d0defa157b6a0465fe3f2b3a870cd912f1fef71f35
MD5 98076b09962c37a607f50f333f4b8d12
BLAKE2b-256 5c31862fe46c0b89afaade0eefdfee31ff89952306b98bdef48d95d21f7b4ce6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: msgspec_xml-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5758dbbfcaa3286ba85b73ed7d4cbb51a4f0a7cca479d6d14cbfb1564d41dc0c
MD5 b6be564667de50c3cc80fecab8951dd4
BLAKE2b-256 fff4dee7a0f3499448bff15aef66aeffafe23fdfd550cabd2cab1352359644e0

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.1

2 files

This release

0.3.0 This release

2 files

0.2.1

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