Metadata-Version: 2.4
Name: msgspec-xml
Version: 0.2.0
Summary: XML Serialization/Deserialization using msgspec
Project-URL: Homepage, https://pypi.org/project/msgspec-xml
Project-URL: Issues, https://codefloe.com/buriedincode/msgspec-xml/issues
Project-URL: Source, https://codefloe.com/buriedincode/msgspec-xml
Author-email: BuriedInCode <buriedincode@duckpond.nz>
Maintainer-email: BuriedInCode <buriedincode@duckpond.nz>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: msgspec>=0.21.0
Description-Content-Type: text/markdown

# msgspec-xml

[![PyPI - Python](https://img.shields.io/pypi/pyversions/msgspec-xml.svg?logo=Python&label=Python&style=flat-square)](https://pypi.org/p/msgspec-xml/)
[![PyPI - Status](https://img.shields.io/pypi/status/msgspec-xml.svg?logo=Python&label=Status&style=flat-square)](https://pypi.org/p/msgspec-xml/)
[![PyPI - Version](https://img.shields.io/pypi/v/msgspec-xml.svg?logo=Python&label=Version&style=flat-square)](https://pypi.org/p/msgspec-xml/)
[![PyPI - License](https://img.shields.io/pypi/l/msgspec-xml.svg?logo=Python&label=License&style=flat-square)](https://opensource.org/licenses/MIT)

[![prek](https://img.shields.io/badge/prek-enabled-informational?logo=prek&style=flat-square)](https://github.com/j178/prek)
[![Ruff](https://img.shields.io/badge/Ruff-enabled-informational?logo=ruff&style=flat-square)](https://github.com/astral-sh/ruff)
[![ty](https://img.shields.io/badge/ty-enabled-informational?logo=ruff&style=flat-square)](https://github.com/astral-sh/ty)

[![status-badge](https://ci.codefloe.com/api/v1/badges/1329/status.svg)](https://ci.codefloe.com/repos/1329)

XML Serialization/Deserialization using [msgspec](https://github.com/msgspec/msgspec).

## Installation

```sh
pdm add msgspec-xml
```

## Usage

```python
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](https://img.shields.io/matrix/The-Dev-Environment:matrix.org?label=The-Dev-Environment&logo=matrix&style=for-the-badge)](https://matrix.to/#/#The-Dev-Environment:matrix.org)
