Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dapper91/pydantic-xml
python xml for humans
https://github.com/dapper91/pydantic-xml
deserialization lxml parser pydantic python serialization xml
Last synced: 15 days ago
JSON representation
python xml for humans
- Host: GitHub
- URL: https://github.com/dapper91/pydantic-xml
- Owner: dapper91
- License: unlicense
- Created: 2022-04-26T19:28:39.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-10-03T17:38:12.000Z (about 1 month ago)
- Last Synced: 2024-10-09T19:26:54.424Z (27 days ago)
- Topics: deserialization, lxml, parser, pydantic, python, serialization, xml
- Language: Python
- Homepage: https://pydantic-xml.readthedocs.io
- Size: 360 KB
- Stars: 156
- Watchers: 5
- Forks: 16
- Open Issues: 11
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.rst
- License: LICENSE
Awesome Lists containing this project
- awesome-pydantic - pydantic-xml - Pydantic xml extension (Utilities)
- awesome-pydantic - pydantic-xml - Pydantic xml extension (Utilities)
README
pydantic-xml extension
======================.. image:: https://static.pepy.tech/personalized-badge/pydantic-xml?period=month&units=international_system&left_color=grey&right_color=orange&left_text=Downloads/month
:target: https://pepy.tech/project/pydantic-xml
:alt: Downloads/month
.. image:: https://github.com/dapper91/pydantic-xml/actions/workflows/test.yml/badge.svg?branch=master
:target: https://github.com/dapper91/pydantic-xml/actions/workflows/test.yml
:alt: Build status
.. image:: https://img.shields.io/pypi/l/pydantic-xml.svg
:target: https://pypi.org/project/pydantic-xml
:alt: License
.. image:: https://img.shields.io/pypi/pyversions/pydantic-xml.svg
:target: https://pypi.org/project/pydantic-xml
:alt: Supported Python versions
.. image:: https://codecov.io/gh/dapper91/pydantic-xml/branch/master/graph/badge.svg
:target: https://codecov.io/gh/dapper91/pydantic-xml
:alt: Code coverage
.. image:: https://readthedocs.org/projects/pydantic-xml/badge/?version=stable&style=flat
:alt: ReadTheDocs status
:target: https://pydantic-xml.readthedocs.io``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 supportWhat is not supported?
______________________- `dataclasses `_
- `callable discriminators `_Getting started
---------------The following model fields binding:
.. code-block:: python
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 textclass 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 childrendefines the XML document:
.. code-block:: xml
https://www.spacex.com
Several launch vehicles
Starlink
Starship
See `documentation `_ for more details.