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.
Release files for pydantic-xml 2.21.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pydantic_xml-2.21.1.tar.gz | 26.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pydantic_xml-2.21.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 70.5 kB
Release files / pydantic_xml-2.21.1.tar.gz
| Download URL | pydantic_xml-2.21.1.tar.gz |
|---|---|
| Size | 26.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
43488d244375d9fbaa593d8c0435f8b0a940d7e594fded647383ff223af2baac
|
|
BLAKE2b-256 checksum How to use checksums |
2c335a24758a8fdf2b3ed09799fd426681eb2ff3a3a2d21ab08697c54730935e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.14.6 Linux/6.17.0-1020-azure
|
Release files / pydantic_xml-2.21.1-py3-none-any.whl
| Download URL | pydantic_xml-2.21.1-py3-none-any.whl |
|---|---|
| Size | 43.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c0469622c344485c328213fa18ff49542b814a9770afcfc6810e9771401d9236
|
|
BLAKE2b-256 checksum How to use checksums |
3959a3b3c08b6755d46d38a3f499dbc525a0eedcf575a6e2cc0dbad3d4755bb1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.14.6 Linux/6.17.0-1020-azure
|