Samples Modeling
The code generator supports processing xml/json documents directly. That means even without a schema you can easily create at the very least an initial draft of your models just from samples. If you use a directory with multiple samples the transformer will merge and flatten duplicate classes, fields and field types.
XML Documents
$ xsdata --package tests.fixtures.artists tests/fixtures/artists
<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">
<artist id="1f9df192-a621-4f54-8850-2c5373b7eac9" type="Person" type-id="b6e035f4-3ce9-331c-97df-83397230b0df">
<name>Ludwig van Beethoven</name>
<sort-name>Beethoven, Ludwig van</sort-name>
<disambiguation>German composer</disambiguation>
<ipi>00002507239</ipi>
<ipi-list>
<ipi>00002507239</ipi>
</ipi-list>
<isni-list>
<isni>0000000121268987</isni>
</isni-list>
<gender id="36d3d30a-839d-3eda-8cb3-29be4384e4a9">Male</gender>
<country>DE</country>
<area id="85752fda-13c4-31a3-bee5-0e5cb1f51dad">
<name>Germany</name>
<sort-name>Germany</sort-name>
<iso-3166-1-code-list>
<iso-3166-1-code>DE</iso-3166-1-code>
</iso-3166-1-code-list>
</area>
<begin-area id="b86b7e97-c4e2-4ec2-942b-5a6cd8eea1da">
<name>Bonn</name>
<sort-name>Bonn</sort-name>
</begin-area>
<end-area id="afff1a94-a98b-4322-8874-3148139ab6da">
<name>Wien</name>
<sort-name>Wien</sort-name>
<iso-3166-2-code-list>
<iso-3166-2-code>AT-9</iso-3166-2-code>
</iso-3166-2-code-list>
</end-area>
<life-span>
<begin>1770-12-17</begin>
<end>1827-03-26</end>
<ended>true</ended>
</life-span>
<alias-list count="31">
<alias sort-name="Beethoven" type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc">Beethoven</alias>
<alias sort-name="Beethoven _ Ludwig Van">Beethoven _ Ludwig Van</alias>
<alias sort-name="Beethoven, Ludwig">Beethoven, Ludwig</alias>
<alias sort-name="Beethoven, Ludwig Van">Beethoven, Ludwig Van</alias>
<alias sort-name="Beethoven, Ludwig Van (1770 - 1827)">Beethoven, Ludwig Van (1770 - 1827)</alias>
<alias sort-name="Beethoven, Ludwig Von">Beethoven, Ludwig Von</alias>
<alias sort-name="Beethoven, Ludwig van (1770-1827)">Beethoven, Ludwig van (1770-1827)</alias>
<alias sort-name="Beethoven, Ludwig van, 1770-1827">Beethoven, Ludwig van, 1770-1827</alias>
<alias sort-name="Bethoveen" type="Search hint" type-id="1937e404-b981-3cb7-8151-4c86ebfc8d8e">Bethoveen</alias>
<alias sort-name="L v Beethoven">L v Beethoven</alias>
<alias locale="lv" sort-name="Bēthovens, L. Van">L. Van Bēthovens</alias>
<alias sort-name="Beethoven, L. Von">L. Von Beethoven</alias>
<alias sort-name="Beethoven, L. van">L. van Beethoven</alias>
<alias locale="en" sort-name="Beethoven, L.Van">L.Van Beethoven</alias>
<alias sort-name="Beethoven, Ludvig Von">Ludvig Von Beethoven</alias>
<alias sort-name="Beethoven, Ludvig van">Ludvig van Beethoven</alias>
<alias locale="lv" sort-name="Ludvigs van Bēthovens" primary="primary">Ludvigs van Bēthovens</alias>
<alias sort-name="Beethoven, Ludwid van">Ludwid van Beethoven</alias>
<alias sort-name="Beethoven, Ludwig">Ludwig Beethoven</alias>
<alias sort-name="Beethoven, Ludwig Van (1770-1827)">Ludwig Van Beethoven (1770-1827)</alias>
<alias sort-name="Beethoven, Ludwig Von">Ludwig Von Beethoven</alias>
<alias locale="en" sort-name="Beethoven, Ludwig van" type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc" primary="primary">Ludwig van Beethoven</alias>
<alias sort-name="LvB" type="Search hint" type-id="1937e404-b981-3cb7-8151-4c86ebfc8d8e">LvB</alias>
<alias sort-name="bheetoven" type="Search hint" type-id="1937e404-b981-3cb7-8151-4c86ebfc8d8e">bheetoven</alias>
<alias sort-name="Beethoven, Ludwig van" type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc">van Beethoven, Ludwig</alias>
<alias locale="ru" sort-name="Beethoven">Бетховен</alias>
<alias locale="ru" sort-name="Бетховен, Л." type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc">Л. Бетховен</alias>
<alias locale="ja" sort-name="ベートーヴェン" type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc" primary="primary">ベートーヴェン</alias>
<alias locale="ja" sort-name="ベートーヴェン ルートヴィヒヴァン" type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc">ルートヴィヒ・ヴァン・ベートーヴェン</alias>
<alias locale="zh_Hant" sort-name="bèi duō fēn" type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc" primary="primary">貝多芬</alias>
<alias locale="ko" sort-name="Beethoven">베토벤</alias>
</alias-list>
</artist>
</metadata>
<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">
<artist id="66c662b6-6e2f-4930-8610-912e24c63ed1" type="Group" type-id="e431f5f6-b5d2-343d-8b36-72607fffb74b">
<name>AC/DC</name>
<sort-name>AC/DC</sort-name>
<disambiguation>Australian hard rock band</disambiguation>
<isni-list>
<isni>000000012271298X</isni>
</isni-list>
<country>AU</country>
<area id="106e0bec-b638-3b37-b731-f53d507dc00e">
<name>Australia</name>
<sort-name>Australia</sort-name>
<iso-3166-1-code-list>
<iso-3166-1-code>AU</iso-3166-1-code>
</iso-3166-1-code-list>
</area>
<begin-area id="3f179da4-83c6-4a28-a627-e46b4a8ff1ed">
<name>Sydney</name>
<sort-name>Sydney</sort-name>
</begin-area>
<life-span>
<begin>1973-11</begin>
</life-span>
<alias-list count="7">
<alias sort-name="AC DC">AC DC</alias>
<alias sort-name="AC-DC">AC-DC</alias>
<alias sort-name="AC.DC">AC.DC</alias>
<alias sort-name="AC?DC">AC?DC</alias>
<alias sort-name="ACDC">ACDC</alias>
<alias sort-name="AC\DC">AC\DC</alias>
<alias sort-name="Ballbreaker">Ballbreaker</alias>
</alias-list>
</artist>
</metadata>
<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">
<artist id="b95ce3ff-3d05-4e87-9e01-c97b66af13d4" type="Person" type-id="b6e035f4-3ce9-331c-97df-83397230b0df">
<name>Eminem</name>
<sort-name>Eminem</sort-name>
<ipi>00354929235</ipi>
<ipi-list>
<ipi>00354929235</ipi>
<ipi>00354929431</ipi>
</ipi-list>
<isni-list>
<isni>0000000117699370</isni>
<isni>0000000368611900</isni>
</isni-list>
<gender id="36d3d30a-839d-3eda-8cb3-29be4384e4a9">Male</gender>
<country>US</country>
<area id="489ce91b-6658-3307-9877-795b68554c98">
<name>United States</name>
<sort-name>United States</sort-name>
<iso-3166-1-code-list>
<iso-3166-1-code>US</iso-3166-1-code>
</iso-3166-1-code-list>
</area>
<begin-area id="bfae8151-2ba2-4f8f-bf2e-8fc16ce352c6">
<name>St. Joseph</name>
<sort-name>St. Joseph</sort-name>
</begin-area>
<life-span>
<begin>1972-10-17</begin>
</life-span>
<alias-list count="13">
<alias sort-name="EMINƎM" type="Search hint" type-id="1937e404-b981-3cb7-8151-4c86ebfc8d8e">EMINƎM</alias>
<alias sort-name="Em" type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc">Em</alias>
<alias locale="en" sort-name="Eminem" type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc" primary="primary">Eminem</alias>
<alias sort-name="EminemMusic" type="Search hint" type-id="1937e404-b981-3cb7-8151-4c86ebfc8d8e">EminemMusic</alias>
<alias sort-name="M&M" type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc">M&M</alias>
<alias sort-name="M. Mathers" type="Search hint" type-id="1937e404-b981-3cb7-8151-4c86ebfc8d8e">M. Mathers</alias>
<alias sort-name="Marshall B. Mathers III" type="Search hint" type-id="1937e404-b981-3cb7-8151-4c86ebfc8d8e">Marshall B. Mathers III</alias>
<alias sort-name="Mathers, Marshall Bruce, III" type="Legal name" type-id="d4dcd0c0-b341-3612-a332-c0ce797b25cf">Marshall Bruce Mathers III</alias>
<alias sort-name="Marshall Mathers III" type="Search hint" type-id="1937e404-b981-3cb7-8151-4c86ebfc8d8e">Marshall Mathers III</alias>
<alias sort-name="Ominem">Ominem</alias>
<alias sort-name="Slim Shady" type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc">Slim Shady</alias>
<alias sort-name="The Real Slim Shady">The Real Slim Shady</alias>
<alias locale="ja" sort-name="エミネム" type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc" primary="primary">エミネム</alias>
</alias-list>
</artist>
</metadata>
from dataclasses import dataclass, field
from typing import List, Optional, Union
from xsdata.models.datatype import XmlDate, XmlPeriod
__NAMESPACE__ = "http://musicbrainz.org/ns/mmd-2.0#"
@dataclass
class Alias:
class Meta:
name = "alias"
namespace = "http://musicbrainz.org/ns/mmd-2.0#"
locale: Optional[str] = field(
default=None,
metadata={
"type": "Attribute",
},
)
sort_name: Optional[str] = field(
default=None,
metadata={
"name": "sort-name",
"type": "Attribute",
"required": True,
},
)
type_value: Optional[str] = field(
default=None,
metadata={
"name": "type",
"type": "Attribute",
},
)
type_id: Optional[str] = field(
default=None,
metadata={
"name": "type-id",
"type": "Attribute",
},
)
primary: Optional[str] = field(
default=None,
metadata={
"type": "Attribute",
},
)
value: str = field(
default="",
metadata={
"required": True,
},
)
@dataclass
class BeginArea:
class Meta:
name = "begin-area"
namespace = "http://musicbrainz.org/ns/mmd-2.0#"
id: Optional[str] = field(
default=None,
metadata={
"type": "Attribute",
"required": True,
},
)
name: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
sort_name: Optional[str] = field(
default=None,
metadata={
"name": "sort-name",
"type": "Element",
"required": True,
},
)
@dataclass
class Gender:
class Meta:
name = "gender"
namespace = "http://musicbrainz.org/ns/mmd-2.0#"
id: Optional[str] = field(
default=None,
metadata={
"type": "Attribute",
"required": True,
},
)
value: str = field(
default="",
metadata={
"required": True,
},
)
@dataclass
class IpiList:
class Meta:
name = "ipi-list"
namespace = "http://musicbrainz.org/ns/mmd-2.0#"
ipi: List[str] = field(
default_factory=list,
metadata={
"type": "Element",
"min_occurs": 1,
},
)
@dataclass
class IsniList:
class Meta:
name = "isni-list"
namespace = "http://musicbrainz.org/ns/mmd-2.0#"
isni: List[str] = field(
default_factory=list,
metadata={
"type": "Element",
"min_occurs": 1,
},
)
@dataclass
class Iso31661CodeList:
class Meta:
name = "iso-3166-1-code-list"
namespace = "http://musicbrainz.org/ns/mmd-2.0#"
iso_3166_1_code: Optional[str] = field(
default=None,
metadata={
"name": "iso-3166-1-code",
"type": "Element",
"required": True,
},
)
@dataclass
class Iso31662CodeList:
class Meta:
name = "iso-3166-2-code-list"
namespace = "http://musicbrainz.org/ns/mmd-2.0#"
iso_3166_2_code: Optional[str] = field(
default=None,
metadata={
"name": "iso-3166-2-code",
"type": "Element",
"required": True,
},
)
@dataclass
class LifeSpan:
class Meta:
name = "life-span"
namespace = "http://musicbrainz.org/ns/mmd-2.0#"
begin: Optional[Union[XmlDate, XmlPeriod]] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
end: Optional[XmlDate] = field(
default=None,
metadata={
"type": "Element",
},
)
ended: Optional[bool] = field(
default=None,
metadata={
"type": "Element",
},
)
@dataclass
class AliasList:
class Meta:
name = "alias-list"
namespace = "http://musicbrainz.org/ns/mmd-2.0#"
count: Optional[int] = field(
default=None,
metadata={
"type": "Attribute",
"required": True,
},
)
alias: List[Alias] = field(
default_factory=list,
metadata={
"type": "Element",
"min_occurs": 1,
},
)
@dataclass
class Area:
class Meta:
name = "area"
namespace = "http://musicbrainz.org/ns/mmd-2.0#"
id: Optional[str] = field(
default=None,
metadata={
"type": "Attribute",
"required": True,
},
)
name: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
sort_name: Optional[str] = field(
default=None,
metadata={
"name": "sort-name",
"type": "Element",
"required": True,
},
)
iso_3166_1_code_list: Optional[Iso31661CodeList] = field(
default=None,
metadata={
"name": "iso-3166-1-code-list",
"type": "Element",
"required": True,
},
)
@dataclass
class EndArea:
class Meta:
name = "end-area"
namespace = "http://musicbrainz.org/ns/mmd-2.0#"
id: Optional[str] = field(
default=None,
metadata={
"type": "Attribute",
"required": True,
},
)
name: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
sort_name: Optional[str] = field(
default=None,
metadata={
"name": "sort-name",
"type": "Element",
"required": True,
},
)
iso_3166_2_code_list: Optional[Iso31662CodeList] = field(
default=None,
metadata={
"name": "iso-3166-2-code-list",
"type": "Element",
"required": True,
},
)
@dataclass
class Artist:
class Meta:
name = "artist"
namespace = "http://musicbrainz.org/ns/mmd-2.0#"
id: Optional[str] = field(
default=None,
metadata={
"type": "Attribute",
"required": True,
},
)
type_value: Optional[str] = field(
default=None,
metadata={
"name": "type",
"type": "Attribute",
"required": True,
},
)
type_id: Optional[str] = field(
default=None,
metadata={
"name": "type-id",
"type": "Attribute",
"required": True,
},
)
name: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
sort_name: Optional[str] = field(
default=None,
metadata={
"name": "sort-name",
"type": "Element",
"required": True,
},
)
disambiguation: Optional[str] = field(
default=None,
metadata={
"type": "Element",
},
)
ipi: Optional[str] = field(
default=None,
metadata={
"type": "Element",
},
)
ipi_list: Optional[IpiList] = field(
default=None,
metadata={
"name": "ipi-list",
"type": "Element",
},
)
isni_list: Optional[IsniList] = field(
default=None,
metadata={
"name": "isni-list",
"type": "Element",
"required": True,
},
)
gender: Optional[Gender] = field(
default=None,
metadata={
"type": "Element",
},
)
country: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
area: Optional[Area] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
begin_area: Optional[BeginArea] = field(
default=None,
metadata={
"name": "begin-area",
"type": "Element",
"required": True,
},
)
end_area: Optional[EndArea] = field(
default=None,
metadata={
"name": "end-area",
"type": "Element",
},
)
life_span: Optional[LifeSpan] = field(
default=None,
metadata={
"name": "life-span",
"type": "Element",
"required": True,
},
)
alias_list: Optional[AliasList] = field(
default=None,
metadata={
"name": "alias-list",
"type": "Element",
"required": True,
},
)
@dataclass
class Metadata:
class Meta:
name = "metadata"
namespace = "http://musicbrainz.org/ns/mmd-2.0#"
artist: Optional[Artist] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
JSON Documents
$ xsdata --package tests.fixtures.series tests/fixtures/series/samples
{
"id": 2,
"name": "Person of Interest",
"type": "Scripted",
"language": "English",
"genres": [
"Action",
"Crime",
"Science-Fiction"
],
"status": "Ended",
"runtime": 60,
"premiered": "2011-09-22",
"officialSite": "http://www.cbs.com/shows/person_of_interest/",
"schedule": {
"time": "22:00",
"days": [
"Tuesday"
]
},
"rating": {
"average": 8.9
},
"network": {
"id": 2,
"name": "CBS",
"country": {
"name": "United States",
"code": "US",
"timezone": "America/New_York"
}
},
"webChannel": null,
"externals": {
"tvrage": 28376,
"imdb": "tt1839578"
},
"summary": "<p>You are being watched. The government has a secret system, a machine that spies on you every hour of every day. I know because I built it. I designed the Machine to detect acts of terror but it sees everything. Violent crimes involving ordinary people. People like you. Crimes the government considered \"irrelevant\". They wouldn't act so I decided I would. But I needed a partner. Someone with the skills to intervene. Hunted by the authorities, we work in secret. You'll never find us. But victim or perpetrator, if your number is up, we'll find you.</p>",
"updated": 1588773151
}
{
"id": 5,
"url": "https://www.tvmaze.com/shows/5/true-detective",
"name": "True Detective",
"type": "Scripted",
"language": "English",
"genres": [
"Drama",
"Crime",
"Thriller"
],
"status": "Running",
"runtime": 60,
"premiered": "2014-01-12",
"officialSite": "http://www.hbo.com/true-detective",
"schedule": {
"time": "21:00",
"days": [
"Sunday"
]
},
"rating": {
"average": 8.3
},
"weight": 97,
"network": {
"name": "HBO",
"country": {
"name": "United States",
"code": "US"
}
},
"externals": {
"tvrage": 31369,
"thetvdb": 270633,
"imdb": "tt2356777"
},
"image": {
"medium": "https://static.tvmaze.com/uploads/images/medium_portrait/178/445621.jpg",
"original": "https://static.tvmaze.com/uploads/images/original_untouched/178/445621.jpg"
},
"summary": "<p>Touch darkness and darkness touches you back. <b>True Detective</b> centers on troubled cops and the investigations that drive them to the edge. Each season features a new cast and a new case.</p>",
"updated": 1614762066,
"_links": {
"self": {
"href": "https://api.tvmaze.com/shows/5"
},
"previousepisode": {
"href": "https://api.tvmaze.com/episodes/1590271"
}
}
}
from dataclasses import dataclass, field
from typing import List, Optional
from xsdata.models.datatype import XmlDate
@dataclass
class Country:
class Meta:
name = "country"
name: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
code: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
timezone: Optional[str] = field(
default=None,
metadata={
"type": "Element",
},
)
@dataclass
class Externals:
class Meta:
name = "externals"
tvrage: Optional[int] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
thetvdb: Optional[int] = field(
default=None,
metadata={
"type": "Element",
},
)
imdb: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
@dataclass
class Image:
class Meta:
name = "image"
medium: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
original: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
@dataclass
class Previousepisode:
class Meta:
name = "previousepisode"
href: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
@dataclass
class Rating:
class Meta:
name = "rating"
average: Optional[float] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
@dataclass
class Schedule:
class Meta:
name = "schedule"
time: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
days: List[str] = field(
default_factory=list,
metadata={
"type": "Element",
"min_occurs": 1,
},
)
@dataclass
class Self:
class Meta:
name = "self"
href: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
@dataclass
class Links:
class Meta:
name = "_links"
self_value: Optional[Self] = field(
default=None,
metadata={
"name": "self",
"type": "Element",
"required": True,
},
)
previousepisode: Optional[Previousepisode] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
@dataclass
class Network:
class Meta:
name = "network"
id: Optional[int] = field(
default=None,
metadata={
"type": "Element",
},
)
name: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
country: Optional[Country] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
@dataclass
class Series:
class Meta:
name = "series"
id: Optional[int] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
url: Optional[str] = field(
default=None,
metadata={
"type": "Element",
},
)
name: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
type_value: Optional[str] = field(
default=None,
metadata={
"name": "type",
"type": "Element",
"required": True,
},
)
language: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
genres: List[str] = field(
default_factory=list,
metadata={
"type": "Element",
"min_occurs": 1,
},
)
status: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
runtime: Optional[int] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
premiered: Optional[XmlDate] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
official_site: Optional[str] = field(
default=None,
metadata={
"name": "officialSite",
"type": "Element",
"required": True,
},
)
schedule: Optional[Schedule] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
rating: Optional[Rating] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
weight: Optional[int] = field(
default=None,
metadata={
"type": "Element",
},
)
network: Optional[Network] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
web_channel: Optional[object] = field(
default=None,
metadata={
"name": "webChannel",
"type": "Element",
},
)
externals: Optional[Externals] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
image: Optional[Image] = field(
default=None,
metadata={
"type": "Element",
},
)
summary: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
updated: Optional[int] = field(
default=None,
metadata={
"type": "Element",
"required": True,
},
)
links: Optional[Links] = field(
default=None,
metadata={
"name": "_links",
"type": "Element",
},
)