pydantic xml extension
Project description
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 '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
Release history Release notifications | RSS feed
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.12.1.tar.gz
(25.5 kB
view hashes)
Built Distribution
Close
Hashes for pydantic_xml-2.12.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5de8394dde00d00a899b85fd8e0b915e6f144a068675d8efcbaa225fdcce3880 |
|
MD5 | 40cb1017096c00375cc7e321216c09c4 |
|
BLAKE2b-256 | cdafa46f432fad304a01f6988f6b430d2819f9dccd6c403e358d9f3c286f1eaf |