Command Line¶
$ xsdata --help
Usage: xsdata [OPTIONS] COMMAND [ARGS]...
xsdata command line interface.
Options:
--version Show the version and exit.
-v, --verbosity LVL Either CRITICAL, ERROR, WARNING, INFO or DEBUG
--help Show this message and exit.
Commands:
generate* Convert schema definitions to code.
download Download a schema or a definition locally with all its...
init-config Create or update a configuration file.
Generate Models¶
$ xsdata generate --help
Usage: xsdata generate [OPTIONS] SOURCE
Convert schema definitions to code.
SOURCE can be either a filepath, directory or url
Options:
--config TEXT Configuration file
--package TEXT Target Package
--output [pydata|plantuml] Output Format
--compound-fields BOOLEAN Use compound fields for repeating choices.
Enable if elements ordering matters for your
case.
--docstring-style [reStructuredText|NumPy|Google|Accessible]
Docstring Style
--wsdl WSDL Mode (experimental)
--print Print output
--ns-struct Use namespaces to group classes in the same
module. Useful against circular import
errors.
--help Show this message and exit.
Generate is the default subcommand of the command line interface and can be omitted.
$ xsdata amadeus/schemas --package amadeus.models
$ xsdata air_v48_0/AirReqRsp.xsd rail_v48_0/RailReqRsp.xsd --package travelport.models
$ xsdata http://www.gstatic.com/localfeed/local_feed.xsd --package feeds --print
SOURCE¶
You can pass the file path or uri to a schema or a whole directory with multiple definitions.
config¶
Specify a configuration file with more advance options.
package¶
Specify where the target module(s) will be created inside the current working directory. eg –package api.models
Note
The cli is relying on the os.path.commonpath of the schemas locations to create the final package structure. If you prefer a more flat structure or you have circular import errors check the option ns-struct.
output¶
Specify the output format
pydata
: Python lib dataclassesplantuml
: PlantUML class diagram
compound-fields¶
The generator by default will flatten repeating choice elements into simple fields. The main disadvantage is that the original elements ordering is lost during marshalling. With this option you can force the generator to create compound list fields to preserve ordering.
See Type: Elements
docstring-style¶
Choose the style of the generated docstrings.
The accessible is a custom style offering easy access to the docstrings of a dataclass’ fields or an enum’ members for doc/api generators.
class RootB(Enum):
"""
:cvar YES: This is an inner enum member documentation. Lorem ipsum
dolor sit amet, consectetur adipiscing elit. Etiam mollis.
:cvar NO: Lorem ipsum dolor
"""
YES = "Yes"
NO = "No"
class RootD(Enum):
TRUE_VALUE = "true"
FALSE_VALUE = "false"
@dataclass
class Root:
"""This is the root type documentation. Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Morbi dapibus.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec
imperdiet lacus sed sagittis scelerisque. Ut sodales metus: "sit",
"amet", "lectus"
:ivar a: This is an inner type field documentation. Lorem ipsum
dolor sit amet, consectetur adipiscing elit. Aliquam nec.
:ivar b: This is a second root type field documentation.
:ivar c:
:ivar d:
"""
class Meta:
namespace = "urn:docs"
a: Optional["Root.A"] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)
b: Optional[RootB] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)
c: Optional[RootEnum] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)
d: Optional[RootD] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)
@dataclass
class A:
"""
This is an inner type documentation.
:ivar sub_a: This is an inner type field documentation. Lorem
ipsum dolor sit amet, consectetur adipiscing elit. Vivamus
efficitur.
"""
sub_a: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)
class RootB(Enum):
"""
Properties
----------
YES: This is an inner enum member documentation. Lorem ipsum dolor
sit amet, consectetur adipiscing elit. Etiam mollis.
NO: Lorem ipsum dolor
"""
YES = "Yes"
NO = "No"
class RootD(Enum):
TRUE_VALUE = "true"
FALSE_VALUE = "false"
@dataclass
class Root:
"""This is the root type documentation. Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Morbi dapibus.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec
imperdiet lacus sed sagittis scelerisque. Ut sodales metus: "sit",
"amet", "lectus"
Parameters
----------
a: This is an inner type field documentation. Lorem ipsum dolor sit
amet, consectetur adipiscing elit. Aliquam nec.
b: This is a second root type field documentation.
c:
d:
"""
class Meta:
namespace = "urn:docs"
a: Optional["Root.A"] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)
b: Optional[RootB] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)
c: Optional[RootEnum] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)
d: Optional[RootD] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)
@dataclass
class A:
"""
This is an inner type documentation.
Parameters
----------
sub_a: This is an inner type field documentation. Lorem ipsum
dolor sit amet, consectetur adipiscing elit. Vivamus
efficitur.
"""
sub_a: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)
class RootB(Enum):
"""
Attributes
YES: This is an inner enum member documentation. Lorem ipsum
dolor sit amet, consectetur adipiscing elit. Etiam mollis.
NO: Lorem ipsum dolor
"""
YES = "Yes"
NO = "No"
class RootD(Enum):
TRUE_VALUE = "true"
FALSE_VALUE = "false"
@dataclass
class Root:
"""This is the root type documentation. Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Morbi dapibus.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec
imperdiet lacus sed sagittis scelerisque. Ut sodales metus: "sit",
"amet", "lectus"
Attributes
a: This is an inner type field documentation. Lorem ipsum dolor
sit amet, consectetur adipiscing elit. Aliquam nec.
b: This is a second root type field documentation.
c:
d:
"""
class Meta:
namespace = "urn:docs"
a: Optional["Root.A"] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)
b: Optional[RootB] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)
c: Optional[RootEnum] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)
d: Optional[RootD] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)
@dataclass
class A:
"""
This is an inner type documentation.
Attributes
sub_a: This is an inner type field documentation. Lorem
ipsum dolor sit amet, consectetur adipiscing elit.
Vivamus efficitur.
"""
sub_a: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)
class RootB(Enum):
YES = "Yes"
NO = "No"
RootB.YES.__doc__ = (
"This is an inner enum member documentation. Lorem ipsum dolor sit amet, "
"consectetur adipiscing elit. Etiam mollis."
)
RootB.NO.__doc__ = "Lorem ipsum dolor"
class RootD(Enum):
TRUE_VALUE = "true"
FALSE_VALUE = "false"
@dataclass
class Root:
"""This is the root type documentation. Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Morbi dapibus.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec
imperdiet lacus sed sagittis scelerisque. Ut sodales metus: "sit",
"amet", "lectus"
"""
class Meta:
namespace = "urn:docs"
a: Optional["Root.A"] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
"doc": (
"This is an inner type field documentation.\nLorem ipsum dolor"
" sit amet, consectetur adipiscing elit. Aliquam nec."
),
}
)
b: Optional[RootB] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
"doc": "This is a second root type field documentation.",
}
)
c: Optional[RootEnum] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)
d: Optional[RootD] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)
@dataclass
class A:
"""
This is an inner type documentation.
"""
sub_a: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
"doc": (
"This is an inner type field documentation.\nLorem ipsum dolor"
" sit amet, consectetur adipiscing elit. Vivamus efficitur."
),
}
)
verbosity¶
Specify the log level, default is INFO
Available options: CRITICAL
, ERROR
, WARNING
, INFO
or DEBUG
wsdl¶
Generate models and services from a wsdl source.
Experimental
This feature is experimental and only a small subset of features have been implemented, WSDL 1.1 & SOAP 1.1 bindings.
print¶
Redirect generated code to stdOut instead of writing the output to the target files.
ns-struct¶
Group classes by the target namespace they were defined. This option creates a more flat package structure and solves many circular import errors.
Initialize Config¶
Initialize a project configuration with more advanced features, see more.
$ xsdata init-config --help
Usage: xsdata init-config [OPTIONS] [OUTPUT]
Create or update a configuration file.
Options:
--print Print output
--help Show this message and exit.
$ xsdata amadeus/schemas --config amadeus/.xsdata.xml
Download Schemas¶
$ xsdata download --help
Usage: xsdata download [OPTIONS] SOURCE
Download a schema or a definition locally with all its dependencies.
Options:
--output PATH Output directory, default cwd
--help Show this message and exit.
Examples
Check the Demos and the samples repo for more ✨✨✨