Getting started

Prerequisites

Make sure you have python >= 3.6 and pip up and running.

$ python --version
Python 3.7.3
$ pip --version
pip 20.2.2 from /home/docs/checkouts/readthedocs.org/user_builds/xsdata/envs/v20.9/lib/python3.7/site-packages/pip (python 3.7)

Warning

In python 3.6 the typing module is flattening subclasses in unions, this may affect how values are converted.

There is no official workaround because it’s not very common, if you like monkey patching then take a look here typing._remove_dups_flatten()

>>> from dataclasses import dataclass
>>> from typing import Union, get_type_hints
>>>
>>> @dataclass
... class Example:
...     value: Union[int, bool, str, float]
...
>>> get_type_hints(Example)
{'value': typing.Union[int, str, float]}
>>> issubclass(bool, int)
True

Install xsData

Install xsData package using pip.

pip install xsdata

Verify installation using the cli entry point.

$ xsdata --help
Usage: xsdata [OPTIONS] SOURCE

  Convert schema definitions to code.

  SOURCE can be either a filepath, directory or url

Options:
  --package TEXT              Target Package  [required]
  --output [pydata|plantuml]  Output Format
  --wsdl                      WSDL Mode (experimental)
  --print                     Print output
  --ns-struct                 Use namespaces to group classes in the same
                              module. Useful against circular import errors.

  --version                   Show the version and exit.
  -v, --verbosity LVL         Either CRITICAL, ERROR, WARNING, INFO or DEBUG
  --help                      Show this message and exit.

xsData relies on these awesome libraries