Command Line#
Make sure the cli requirements are installed.
$ pip install xsdata[cli]
xsdata --help
Usage: xsdata [OPTIONS] COMMAND [ARGS]...
xsdata command line interface.
Options:
--version Show the version and exit.
--help Show this message and exit.
Commands:
generate* Generate code from xml schemas, webservice definitions and...
download Download a schema or a definition locally with all its...
init-config Create or update a configuration file.
Generate Code#
xsdata generate --help
Usage: xsdata generate [OPTIONS] SOURCE
Generate code from xml schemas, webservice definitions and any xml or json
document.
The input source can be either a filepath, uri or a directory containing
xml, json, xsd and wsdl files.
Options:
-r, --recursive Search files recursively in the source
directory
-c, --config TEXT Project configuration
-pp, --print Print output
-p, --package TEXT Target package, default: generated
-o, --output [dataclasses] Output format name, default: dataclasses
--repr / --no-repr Generate __repr__ method, default: true
--eq / --no-eq Generate __eq__ method, default: true
--order / --no-order Generate __lt__, __le__, __gt__, and __ge__
methods, default: false
--unsafe-hash / --no-unsafe-hash
Generate __hash__ method if not frozen,
default: false
--frozen / --no-frozen Enable read only properties, default false
--slots / --no-slots Enable __slots__, default: false,
python>=3.10 Only
--kw-only / --no-kw-only Enable keyword only arguments, default:
false, python>=3.10 Only
-ss, --structure-style [filenames|namespaces|clusters|single-package|namespace-clusters]
Output structure style, default: filenames
-ds, --docstring-style [reStructuredText|NumPy|Google|Accessible|Blank]
Docstring style, default: reStructuredText
--relative-imports / --no-relative-imports
Use relative imports, default: false
--compound-fields / --no-compound-fields
Use compound fields for repeatable elements,
default: false
-mll, --max-line-length INTEGER
Adjust the maximum line length, default: 79
--postponed-annotations / --no-postponed-annotations
Enable postponed evaluation of annotations,
default: false, python>=3.7 Only
--unnest-classes / --no-unnest-classes
Move inner classes to upper level, default:
false
--help Show this message and exit.
$ xsdata amadeus/schemas --package amadeus.models
$ xsdata air_v48_0/AirReqRsp.xsd --package travelport.models
$ xsdata http://www.gstatic.com/localfeed/local_feed.xsd --package feeds --print
$ xsdata https://musicbrainz.org/ws/2/artist/1f9df192-a621-4f54-8850-2c5373b7eac9 --print
Output plugins#
PlantUML class diagrams
Circular imports#
Python is vulnerable to xsd circular imports. xsData by default groups all classes by the schema location they are defined. This works well for schemas that avoid circular imports. If you get import errors you should try one of the alternative structure styles.
clusters
This style will identify the strongly connected classes and will group them together, creating as many modules as possible. The modules are named after the the main class of the group.
$ xsdata schema.xsd --package models --structure-style clusters
namespaces
This style will group classes by the target namespace they were originally defined. It works well when the types of a namespace are spread across multiple schemas eg. type substitutions, redefines.
$ xsdata schema.xsd --package models --structure-style namespaces
Since v21.8, the generator converts namespaces to packages similar to jaxb in order to facilitate runs against multiple schemas from the same vendor.
Examples (before naming conventions) |
|
---|---|
org.w3.xml.1998.namespace |
|
myNS.tempuri.org |
org.tempuri.myNS |
com.25hoursaday.address |
namespace-clusters
This style combines the clusters and the namespace styles. It will fail if there are strongly connected classes in the same graph from different namespaces.
$ xsdata schema.xsd --package models --structure-style namespace-clusters
single-package
This style will group all classes together into a single package eliminating imports altogether.
$ xsdata schema.xsd --package models --structure-style single-package
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:
-pp, --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:
-o, --output PATH Output directory, default cwd
--help Show this message and exit.
Examples
Check the Examples and the samples repo for more ✨✨✨