Python, NumPy interop - itkwasm python documentation
Description: itkwasm interface types, used in function calls, are standard Python dataclasses. These interface types are composed of standard Python datatypes, dict, list, float, int, and NumPy arrays. Convert ...

Hide navigation sidebar
Hide table of contents sidebar
Back to top
Edit this page
Toggle table of contents sidebar

# Python, NumPy interop

`itkwasm` interface types, used in function calls, are standard Python `dataclasses`. These interface types are composed of standard Python datatypes, `dict`, `list`, `float`, `int`, and NumPy arrays.

## Convert from `itkwasm` to `dict`

To convert from an `itkwasm` dataclass interface type to a Python dictionary, use `asdict` from the Python standard library.

An example with `itkwasm.Image`:

    from itkwasm import Image
    image = Image()

    from dataclasses import asdict
    image_dict = asdict(image)

## Convert from `dict` to `itkwasm`

To convert back to an `itkwasm` interface type, use the `**` Python operator to expand the dictionary into keyword arguments for the dataclass constructor.

    from itkwasm import Image
    image = Image(**image_dict)