Skip to content

Introduction

The code generator works with:

  • XML Schemas v1.0 & v1.1
  • WSDL v1.1 definitions with SOAP v1.1 bindings
  • DTD external definitions
  • Directly from XML and JSON Documents

The xsdata.codegen.transformer will detect and switch parsers based on the resource extension otherwise it will do some heuristic content searches. Before you start make sure the cli requirements are installed.

$ pip install xsdata[cli]

Command Line Tool

$ xsdata generate --help
========= xsdata v24.5 / Python 3.11.6 / Platform linux =========

Usage: xsdata generate [OPTIONS] SOURCE

  Generate code from xsd, dtd, wsdl, xml and json files.

  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
  --cache                         Cache sources loading
  --debug                         Show debug messages
  -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 [default: False]
  --frozen / --no-frozen          Enable read only properties [default: False]
  --slots / --no-slots            Enable __slots__, python>=3.10 Only
                                  [default: False]
  --kw-only / --no-kw-only        Enable keyword only arguments, python>=3.10
                                  Only [default: False]
  -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]
  --wrapper-fields / --no-wrapper-fields
                                  Generate wrapper fields [default: False]
  -mll, --max-line-length INTEGER
                                  Adjust the maximum line length [default: 79]
  --subscriptable-types / --no-subscriptable-types
                                  Use PEP-585 generics for standard
                                  collections, python>=3.9 Only [default:
                                  False]
  --union-type / --no-union-type  Use PEP-604 union type, python>=3.10 Only
                                  [default: False]
  --postponed-annotations / --no-postponed-annotations
                                  Use 563 postponed evaluation of annotations
                                  [default: False]
  --unnest-classes / --no-unnest-classes
                                  Move inner classes to upper level [default:
                                  False]
  --ignore-patterns / --no-ignore-patterns
                                  Ignore pattern restrictions [default: False]
  --include-header / --no-include-header
                                  Include a header with codegen information in
                                  the output [default: False]
  --help                          Show this message and exit.

Use a directory as source

You can instruct the cli to search all subdirectories recursively with the -r, --recursive flag.

$ xsdata project/schemas
$ xsdata project/schemas --recursive

Use a filename or URI as source

$ xsdata project/schemas/feed.xsd
$ xsdata http://www.gstatic.com/localfeed/local_feed.xsd