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.
  -v, --verbosity LVL  Either CRITICAL, ERROR, WARNING, INFO or DEBUG
  --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:
  -c, --config TEXT               Specify a configuration file with advanced
                                  options.
  -p, --package TEXT              Specify the target package to be created
                                  inside the current working directory
                                  Default: generated
                                  
                                  The generated module structure relies on the
                                  common input source path
                                  
                                  Use the --ns-struct option for a more flat
                                  structure and to avoid circular import
                                  errors.
  -o, --output [dataclasses]      Specify the output format from the builtin
                                  code generator and any third party installed
                                  plugins. Default: dataclasses
  -ds, --docstring-style [reStructuredText|NumPy|Google|Accessible|Blank]
                                  Specify the docstring style for the default
                                  output format. Default: reStructuredText
  -ns, --ns-struct                Use namespaces to group classes in modules.
                                  Useful against circular import errors.
                                  Deprecated use '--structure-style
                                  namespaces'
  -ss, --structure-style [filenames|namespaces|single-package]
                                  Specify a structure style to organize
                                  classes Default: filenames
                                  
                                  filenames: groups classes by the schema
                                  location
                                  
                                  namespaces: group classes by the target
                                  namespace
                                  
                                  single-package: group all classes together
  -cf, --compound-fields          Use compound fields for repeating choices in
                                  order to maintain elements ordering between
                                  data binding operations.
  -pp, --print                    Print to console instead of writing the
                                  generated output to files
  --help                          Show this message and exit.
Scan directory for xsd, wsdl, xml files
$ xsdata amadeus/schemas --package amadeus.models
Convert a local schema
$ xsdata air_v48_0/AirReqRsp.xsd --package travelport.models
Convert a remote schema
$ xsdata http://www.gstatic.com/localfeed/local_feed.xsd --package feeds --print
Convert a remote xml file
$ xsdata https://musicbrainz.org/ws/2/artist/1f9df192-a621-4f54-8850-2c5373b7eac9 --print

Output plugins

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.

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

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

Warning

Auto locating types during parsing might not work since all classes are bundled together under the same module namespace.

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 ✨✨✨