pydantic-xml
pydantic xml extension
Decision gist · record as of 2026-08-14
Yes. Low install friction, active maintenance, no known vulnerabilities, permissive license, and solid popularity (top 5000 PyPI packages). Install if you need to work with XML in a pydantic-native way; skip only if you have no XML in your project or prefer a different serialization format.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Low friction: pure Python wheel with only pydantic and pydantic-core as runtime dependencies.
- Active maintenance with a release 6 days ago; repository shows steady activity and 255 stars.
License · maintenance · safety
Unlicense (permissive) — Licensed under Unlicense (permissive public domain), so you can use, modify, and distribute freely without restriction or attribution requirement.
last release 2026-08-08 (6 days) · last repo commit 2026-08-08 · 255 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 2,507,149 downloads/mo, #3,035 on PyPI
Alternatives
Verify before relying
pip install pydantic-xml
from pydantic_xml import BaseXmlModel, attr, element
from typing import List
class Product(BaseXmlModel):
status: str = attr()
title: str
class Company(BaseXmlModel):
trade_name: str = attr(name='trade-name')
products: List[Product] = element(tag='product')
xml_str = '<Company trade-name="SpaceX"><product status="active">Starship</product></Company>'
company = Company.from_xml(xml_str)
xml_out = company.to_xml()- Whether lxml is required or optional; fact sheet lists it as a supported parser but does not clarify if it's a hard dependency.
- Performance characteristics when handling large XML documents or deeply nested structures.
What it is and what it does
Pydantic-xml is a pydantic extension that bridges Python dataclass-like models and XML documents. It lets you declare a pydantic model with fields that map to XML attributes (via `attr()`), child elements (via `element()`), or text content, then automatically serialize instances to XML or deserialize XML back into typed Python objects. The binding is declarative and integrates with pydantic's type system, so you get validation, optional fields, unions, generics, and computed fields all working with XML.
The package supports both pydantic v1 and v2, works with standard library `xml.etree.ElementTree` or the faster lxml parser, and handles Python collection types like List, Dict, Set, and Tuple. It does not support pydantic dataclasses or callable discriminators in unions. Most use cases involve APIs or configuration files where XML is the wire format but you want to work with typed Python objects.
Use it for
- Parse XML configuration files into typed pydantic models with validation, then serialize changes back to XML.
- Consume SOAP or XML-based REST APIs by mapping XML responses to pydantic models automatically.
- Build XML document generators where you define the structure as a pydantic model and serialize instances to XML.
- Migrate legacy XML-based systems to Python by treating XML as a serialization format for modern typed models.
- Validate and transform XML data pipelines using pydantic's rich validation and computed field features.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
Low install friction, active maintenance, no known vulnerabilities, permissive license, and solid popularity (top 5000 PyPI packages). Install if you need to work with XML in a pydantic-native way; skip only if you have no XML in your project or prefer a different serialization format.
Install
pydantic-xml on PyPI
Before you install
Low friction: pure Python wheel with only pydantic and pydantic-core as runtime dependencies. Active maintenance with a release 6 days ago; repository shows steady activity and 255 stars.
License in practice
Licensed under Unlicense (permissive public domain), so you can use, modify, and distribute freely without restriction or attribution requirement.
Quickstart
pip install pydantic-xml
from pydantic_xml import BaseXmlModel, attr, element
from typing import List
class Product(BaseXmlModel):
status: str = attr()
title: str
class Company(BaseXmlModel):
trade_name: str = attr(name='trade-name')
products: List[Product] = element(tag='product')
xml_str = '<Company trade-name="SpaceX"><product status="active">Starship</product></Company>'
company = Company.from_xml(xml_str)
xml_out = company.to_xml()
Verify before relying
- Whether lxml is required or optional; fact sheet lists it as a supported parser but does not clarify if it's a hard dependency.
- Performance characteristics when handling large XML documents or deeply nested structures.
Package facts
| License | Unlicense permissive |
| Python support | Supports the current Python release >=3.8 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 2 packagespydanticpydantic-core |
| Maintenance | Actively maintained 6 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,507,149 / month, #3,035 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableFramework :: PydanticFramework :: Pydantic :: 1Framework :: Pydantic :: 2Intended Audience :: DevelopersLicense :: OSI ApprovedLicense :: Public DomainNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: LibrariesTopic :: Text Processing :: Markup :: XMLTyping :: Typed |
Evidence: pydantic_xml-2.21.1-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “pydantic xml serialization”
- pydantic-xmlPydantic-xml adds XML serialization and deserialization to pydantic…
- xsdata-pydanticGenerates pydantic models from XML and JSON schemas, then parses and…
- fhir-coreProvides Pydantic V2-based abstract base classes and primitive…
Give your agent the search over MCP, or paste the wish link into any chat.
More Libraries packages
urllib3 is an HTTP client library that provides thread-safe connection pooling, SSL/TLS verification, multipart file uploads, request retries, compression support, and proxy handling for Python applications.
Requests is a Python HTTP library that simplifies sending HTTP/1.1 requests with automatic handling of headers, authentication, cookies, and response parsing.
Pluggy provides a plugin system that lets you define hook specifications and register implementations to be called in sequence, enabling extensible Python applications without tight coupling.
Install it if you're building an extensible application or framework.
Provides parsing, arithmetic, and recurrence rule computation for dates and times, with timezone support and iCalendar RFC compliance.
Install it if you need to parse flexible date strings, compute relative dates, handle timezones, or work with recurrence rules—it's the de facto choice for these tasks.
Six provides utility functions to write Python code that runs on both Python 2.7 and Python 3.3+, smoothing over language differences between the two versions.
pytest is a testing framework that lets you write test functions using plain assert statements and automatically discovers and runs them, with detailed failure reporting.
See also xsdata-pydantic · py-serializable · xml-python · PyXB-X · et-xmlfile · py-avro-schema · maec · pyangbind · xsdata · pydantic-scim