Skip to main content

pydantic xml extension

Project description

Downloads/month Build status License Supported Python versions Code coverage ReadTheDocs status

pydantic-xml is a pydantic extension providing model fields xml binding and xml serialization / deserialization. It is closely integrated with pydantic which means it supports most of its features.

Features

  • pydantic v1 / v2 support

  • flexible attributes, elements and text binding

  • python collection types support (Dict, TypedDict, List, Set, Tuple, …)

  • Union type support

  • pydantic generic models support

  • pydantic computed fields support

  • lxml xml parser support

  • xml.etree.ElementTree standard library xml parser support

What is not supported?

Getting started

The following model fields binding:

class Product(BaseXmlModel):
    status: Literal['running', 'development'] = attr()  # extracted from the 'status' attribute
    launched: Optional[int] = attr(default=None)  # extracted from the 'launched' attribute
    title: str  # extracted from the element text


class Company(BaseXmlModel):
    trade_name: str = attr(name='trade-name')  # extracted from the 'trade-name' attribute
    website: HttpUrl = element()  # extracted from the 'website' element text
    products: List[Product] = element(tag='product', default=[])  # extracted from the 'Company' element's children

defines the XML document:

<Company trade-name="SpaceX">
    <website>https://www.spacex.com</website>
    <product status="running" launched="2013">Several launch vehicles</product>
    <product status="running" launched="2019">Starlink</product>
    <product status="development">Starship</product>
</Company>

See documentation for more details.

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

pydantic_xml-2.17.2.tar.gz (25.9 kB view details)

Uploaded Source

Built Distribution

pydantic_xml-2.17.2-py3-none-any.whl (42.1 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_xml-2.17.2.tar.gz.

File metadata

  • Download URL: pydantic_xml-2.17.2.tar.gz
  • Upload date:
  • Size: 25.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.5 Linux/6.11.0-1015-azure

File hashes

Hashes for pydantic_xml-2.17.2.tar.gz
Algorithm Hash digest
SHA256 0e0f2ae84518198373b593eca58bba12b08c1a7ace368dd4ed12b60babc8182d
MD5 00fe9c4b8af65b03e53df9b48473b072
BLAKE2b-256 d87a1a801e578ee6c9e7707de9eef0b7b232381a77e00ecdc5dfa3ccb2565721

See more details on using hashes here.

File details

Details for the file pydantic_xml-2.17.2-py3-none-any.whl.

File metadata

  • Download URL: pydantic_xml-2.17.2-py3-none-any.whl
  • Upload date:
  • Size: 42.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.5 Linux/6.11.0-1015-azure

File hashes

Hashes for pydantic_xml-2.17.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3990908939ecc18f304045f3ee544bbdb68e253248fde20dc1af6829e80c03f5
MD5 d87fff19dca9cb7437294f622baafdce
BLAKE2b-256 66000492d88608d5cdf53f9883fe3274874f4ee8d6f5003ef059cd55c12fe82c

See more details on using hashes here.

Supported by

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