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
Built Distribution
File details
Details for the file pydantic_xml-2.13.0.tar.gz
.
File metadata
- Download URL: pydantic_xml-2.13.0.tar.gz
- Upload date:
- Size: 25.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.6 Linux/6.8.0-1014-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92737661c644681054bb06ed86bac492a905bfda99eaac0659ef470c8589a290 |
|
MD5 | 026b1f20af3952fcc584c189ce928912 |
|
BLAKE2b-256 | d2edd81258b4767073c73dbcfa1f3991f5dad283f6d26e57d85defbf9c9c0b2f |
File details
Details for the file pydantic_xml-2.13.0-py3-none-any.whl
.
File metadata
- Download URL: pydantic_xml-2.13.0-py3-none-any.whl
- Upload date:
- Size: 40.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.6 Linux/6.8.0-1014-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | da6f59041c5f9ef8b33115739e3dfca55d6f8388b89fc6c234406c1c3cbe3acd |
|
MD5 | 009d3e3c67625919ce3c85ccb1a0b208 |
|
BLAKE2b-256 | af8d5e58f254325596ed3b52c571bc5a1781b7953ac9a7a1c2954a811a25f5ba |