xsdata pydantic plugin
Project description
xsdata powered by pydantic!
xsData is a complete data binding library for python allowing developers to access and use XML and JSON documents as simple objects rather than using DOM.
Now powered by pydantic!
Install
$ # Install with cli support
$ pip install xsdata-pydantic[cli]
Generate Models
$ # Generate models
$ xsdata http://rss.cnn.com/rss/edition.rss --output pydantic
Parsing document edition.rss
Analyzer input: 9 main and 0 inner classes
Analyzer output: 9 main and 0 inner classes
Generating package: init
Generating package: generated.rss
from dataclasses import field
from pydantic.dataclasses import dataclass
@dataclass
class Rss:
class Meta:
name = "rss"
version: Optional[float] = field(
default=None,
metadata={
"type": "Attribute",
}
)
channel: Optional[Channel] = field(
default=None,
metadata={
"type": "Element",
}
)
...
XML Parsing
>>> from xsdata_pydantic.bindings import XmlParser
>>> from urllib.request import urlopen
>>> from generated.rss import Rss
>>>
>>> parser = XmlParser()
>>> with urlopen("http://rss.cnn.com/rss/edition.rss") as rq:
... result = parser.parse(rq, Rss)
...
>>> result.channel.item[2].title
"'A total lack of discipline': Clarissa Ward visits abandoned Russian foxholes"
>>> result.channel.item[2].pub_date
'Fri, 08 Apr 2022 22:56:33 GMT'
>>> result.channel.item[2].link
'https://www.cnn.com/videos/world/2022/04/08/ukraine-chernihiv-visit-ward-pkg-tsr-vpx.cnn'
Changelog: 22.10 (2022-10-02)
Initial Release
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
xsdata_pydantic-22.10.tar.gz
(19.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xsdata_pydantic-22.10.tar.gz.
File metadata
- Download URL: xsdata_pydantic-22.10.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ae39e338a42eb9352c8c777cb9095767ed3af0d1c7fd52e76a65846c1ef7920
|
|
| MD5 |
8615f163c1c21ea2aa700b4450548b90
|
|
| BLAKE2b-256 |
5e1c31b899ab1a5f5fc12ccff8e76823b65ccfffdae1f3bf2b2c0ad69341200e
|
File details
Details for the file xsdata_pydantic-22.10-py3-none-any.whl.
File metadata
- Download URL: xsdata_pydantic-22.10-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13fcea627eac593c1e3b9bdccd7bfa82b2a4a09e4c1b9685b57b4389ae3ce2fa
|
|
| MD5 |
1bb1e824c07ad447c7c9c3da51ff9e10
|
|
| BLAKE2b-256 |
4f777a6dcb5b3ea558f7586d9681502a08d7b569f2922dad870e2e4ec6d39454
|