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

  • flexable 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 'website' element

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.1.0.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydantic_xml-2.1.0-py3-none-any.whl (31.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pydantic_xml-2.1.0.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.4 Linux/5.15.0-1041-azure

File hashes

Hashes for pydantic_xml-2.1.0.tar.gz
Algorithm Hash digest
SHA256 cf80426dd32cc41b47b47a5001ec2e1809dd7d7ed0e6e3397ee82579657768be
MD5 0b8cfc5aa384f0ff63bddbc6e3dc9232
BLAKE2b-256 cd8c82c38935f7d9e021bc5e58597f13a1e13dbf87ad44dbb7c8d1b981c86f09

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pydantic_xml-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 31.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.4 Linux/5.15.0-1041-azure

File hashes

Hashes for pydantic_xml-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2b0c577fc3b671a887e58590e464f27cf7f3671f34d37fef20fb70a1df90dca8
MD5 1b35fef1a4dd91094a48073b804a993b
BLAKE2b-256 f15e65bc730ca1c98dcd3a725cd753f8e3e6d7be06e5b26ffb95dbf6782a62c9

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