Introducing a new way to review your PRs.

Read the announcement

insightsoftwareconsortium / itk

Insight Toolkit (ITK) -- Official Repository. ITK builds on a proven, spatially-oriented architecture for processing, segmentation, and registration of scientific images in two, three, or more dimensions.

View on GitHub

19 documents · Updated Nov 23, 2026

docs / python-wrapping

Python wrapping and package runtime

ITK's Python bridge exposes selected C++ classes and template instances through one Python package. It turns wrapping rules into native extension modules, Python proxy code, type information, and a run-time loader that finds and joins these parts when an engineer uses itk.

Wrapping scope

The wrapping scope defines which C++ API is available in Python and which compiled type variants users can select. It is part of the module build contract, so changes to classes, templates, scalar types, or image dimensions change the Python surface.

Wrapping configuration

Each wrapped module declares its Python surface with .wrap files. Shared build settings provide the supported type and dimension choices, while module dependencies control how those choices are made available across the package.

The shared type registry turns those choices into consistent C++ type names, module names, and SWIG names. It also adds variants required by related filters and data types, such as image, vector, tensor, fixed-array, and pixel forms. This keeps dependent wrappers on the same set of compiled types instead of creating separate naming rules.

The wrapper rules can narrow those shared choices for a class. The Cuberille image-to-mesh filter exposes only configured 3D image dimensions and scalar pixel types. The transform-to-strain filter exposes every configured dimension for double and the configured real type. These conditions make the Python surface follow the type combinations that each C++ class can use.

The rules also control the order of template variants. The BSpline transform, initializer, base transform, and interpolation-weight wrappers expose orders 3, 1, and 2 for each wrapped image dimension, with order 3 first so it is the Python default. Related FunctionBase and fixed-array variants provide the types needed by interpolation and BSpline weights.

Modules can also set an explicit submodule order when type discovery needs a stable sequence. For example, IsotropicWavelets exposes its Riesz structure tensor filter through the renamed itkRieszStructureTensorImageFilter.wrap submodule and places it before later filter wrappers.

The build uses CastXML and SWIG to create the Python bridge. CastXML can use a system installation when it meets ITK's minimum version, or ITK can provide a pinned tool build for supported hosts and build it with its compiler dependencies on other hosts. The wrapper build must preserve the compiler and include context used for type discovery.

The generated package configuration carries the selected scalar types and image dimensions into the runtime. It also carries module dependencies, template names, and factory names so the run-time loader can assemble the same surface that the build produced. Python package files and generated stubs are installed under normalized site-package destinations, which keeps build-tree and wheel layouts consistent.

References: Wrapping/ConfigureWrapping.cmake• L7-35 Wrapping/…/CMakeLists.txt• L12-45 Wrapping/…/CMakeLists.txt• L1-49 Wrapping/…/CMakeLists.txt• L52-64 Wrapping/…/CMakeLists.txt• L164-200 Wrapping/…/CMakeLists.txt• L89-114 Wrapping/…/CMakeLists.txt• L149-181 Wrapping/…/CMakeLists.txt• L244-260 Wrapping/…/CMakeLists.txt• L272-377 Wrapping/WrapITKTypes.cmake• L3-53 Wrapping/WrapITKTypes.cmake• L61-190 Wrapping/WrapITKTypes.cmake• L240-316 Wrapping/WrapITKTypes.cmake• L318-389 Modules/…/itkFunctionBase.wrap• L1-42 Modules/…/itkBSplineTransform.wrap• L1-8 Modules/…/itkBSplineTransformInitializer.wrap• L1-13 Modules/…/itkCuberilleImageToMeshFilter.wrap• L1-11 Modules/…/itkTransformToStrainFilter.wrap• L1-12 Modules/…/CMakeLists.txt• L1-11 Modules/…/itkRieszStructureTensorImageFilter.wrap• L1-45 Wrapping/…/CMakeLists.txt• L1-35 Wrapping/…/ModuleConfig.py.in• L1-3

Binding generation

Binding generation converts the selected C++ declarations into SWIG input and then into Python proxy code plus a native extension. The process keeps declaration discovery, type aliases, dependency order, and the generated Python surface aligned.

CastXML type discovery

CastXML reads a generated C++ probe for each wrapping submodule and produces an XML description of the declarations that the wrapper build can see. The probe uses the same headers, compiler settings, include paths, and definitions as the C++ build, so discovery reflects the real target rather than a separate guessed environment.

The CastXML build can use a system executable, but configuration stops when the executable is missing or older than the required minimum. When ITK supplies CastXML, it selects a verified host binary where one is available and otherwise builds CastXML with its pinned LLVM and Clang dependencies. This gives type discovery a known tool contract across supported build hosts.

References: Wrapping/…/itk_auto_load_submodules.cmake• L106-216 Wrapping/…/CMakeLists.txt• L13-49 Wrapping/…/CMakeLists.txt• L52-64 Wrapping/…/CMakeLists.txt• L164-200 Wrapping/…/CMakeLists.txt• L261-398 Wrapping/…/wrap_.cxx.in• L1-18 Wrapping/TypedefMacros.cmake• L467-479

SWIG interface generation

Wrapping/…/igenerator.py turns CastXML declarations into SWIG interfaces. It uses module indexes to share type aliases across dependencies, orders declarations after their base types, and emits the Python rules needed by generated proxies.

The generator also creates snake-case functions for supported process objects. These functions provide a functional Python entry point that accepts Python-friendly inputs, creates the matching process object, and returns its output.

The module end step joins each submodule interface into a module interface. It also emits index data, Python type-hint inputs, snake-case configuration, module configuration, and the native extension target. It handles the native module initialization form used by supported SWIG versions, so the package can load a generated extension without retaining a half-initialized module.

This diagram shows how wrapping choices become the Python package surface.

flowchart LR
    R[Wrapper rules] --> P[C++ probe]
    P --> X[CastXML declaration data]
    X --> I[SWIG interfaces and type indexes]
    I --> S[Python proxy and native extension]
    S --> W[ITK Python package]

References: Wrapping/…/itk_auto_load_submodules.cmake• L310-455 Wrapping/…/itk_end_wrap_module.cmake• L66-203 Wrapping/…/itk_end_wrap_module.cmake• L284-342 Wrapping/…/igenerator.py• L468-488 Wrapping/…/igenerator.py• L1144-1288 Wrapping/…/CMakeLists.txt• L272-377 Wrapping/…/CMakeLists.txt• L389-558

Documentation interface generation

The documentation bridge turns Doxygen XML into SWIG docstring features for the generated Python bindings. The ITK-specific converter can map one C++ name to one or more generated SWIG names, skip empty member documentation, and combine configured input records into one SWIG interface fragment. Missing input records are reported and skipped so one absent source file does not create invalid documentation text.

For each wrapped module, documentation discovery uses the module's own include paths and the include paths of its dependencies. This keeps header lookup aligned with target-based module configuration instead of relying only on directory-level include settings.

References: Wrapping/…/doxy2swig.py• L46-142 Wrapping/…/doxy2swig.py• L327-387 Wrapping/…/itk_doxy2swig.py• L17-95 Wrapping/…/itk_doxy2swig.py• L97-119 Wrapping/TypedefMacros.cmake• L98-104 Wrapping/TypedefMacros.cmake• L201-206 Wrapping/TypedefMacros.cmake• L337-377

Type information

Generated index files map full C++ types to the short names used by SWIG and identify the module that owns each definition. Master indexes connect these maps across module dependencies, which prevents dependent modules from creating a second Python identity for the same wrapped type.

The wrapper generator records class methods, overloads, inheritance, enum values, template status, and construction support. pyi_generator.py combines records for the same class and writes .pyi files for editors and type checkers. The merge keeps the first-seen base-class order and rejects conflicting class metadata.

References: Wrapping/…/igenerator.py• L233-290 Wrapping/…/igenerator.py• L933-986 Wrapping/…/itk_end_wrap_module.cmake• L87-97 Wrapping/…/pyi_generator.py• L432-500 Wrapping/…/pyi_generator_merge_test.py• L29-43

Python support runtime

The Python support runtime connects generated proxy modules to the package-level itk experience. It supplies template selection, native module loading, data conversion, process helpers, and the run-time view of the build's supported types.

Package configuration

Wrapping/…/itkConfig.template.in.py becomes the installed itkConfig.py. It records the relative locations of native libraries, generated proxy code, and module configuration. It also records the supported type and dimension choices that the runtime uses when it describes the package.

Each wrapped module has a generated ModuleConfig.py file. That file names its dependencies, templates, and object factories. A module may add a small import preamble for a required native library path; VtkGlue uses this on Windows to register VTK's DLL directory before Python imports VTK modules.

References: Wrapping/…/itkConfig.template.in.py• L19-33 Wrapping/…/itkConfig.template.in.py• L36-113 Wrapping/…/itkConfig.template.in.py• L142-205 Wrapping/…/ModuleConfig.py.in• L1-3 Modules/…/CMakeLists.txt• L1-29

C type aliases

The runtime gives C primitive types stable ITK names and maps those names to NumPy dtypes. Fixed-width aliases follow the platform's native width, so template selection and array conversion use the same type sizes as the compiled wrapper.

References: Wrapping/…/types.py• L37-120 Wrapping/…/types.py• L154-177 Wrapping/…/test_ctype.py• L25-89

Module assembly

When a module loads, the runtime loads its dependencies first. It then registers the native classes and joins each generated template feature to its Python template family. The result is cached, so later accesses reuse the same Python objects.

References: Wrapping/…/template_class.py• L47-102 Wrapping/…/base.py• L45-81 Wrapping/…/base.py• L83-233

Native object behavior

The common SWIG support rules define the Python behavior of wrapped native objects. They translate selected C++ exceptions to Python exceptions, preserve native object ownership, and add Python protocols for common ITK objects such as images, regions, vectors, metadata, and process objects.

Image objects expose array and buffer views that share image memory when the requested operation permits it. Copy operations remain independent. The rules also preserve the image lifetime while a Python array or memory view uses the shared buffer.

References: Wrapping/…/pyBase.i• L44-121 Wrapping/…/pyBase.i• L336-417 Wrapping/…/pyBase.i• L746-896

Template and process support

The runtime represents a C++ template family as an itkTemplate. A family maps the Python-facing class name to the compiled SWIG class for each supported parameter set, so users can select a wrapped type with bracketed parameters or use an available default.

Template parameters can include another registered template family. The runtime keeps that family as a template argument instead of treating it as an ordinary instance, so distinct variants such as interpolation choices remain distinct and reachable from Python.

Generated process functions use the same template and conversion system. Their decorators accept supported array-like inputs, while their output types describe image, mesh, path, or spatial-object results when the C++ process model provides them. Optional support for xarray, PyTorch, and SimpleITK is enabled only when the corresponding package is available. When an array-like input selects output conversion, the result keeps the input library's data form.

Optional support also treats an installed package that cannot be imported as unavailable. This keeps the core itk import and NumPy or ITK paths usable when an optional package has a broken installation. Invalid template selections produce a TemplateTypeError that names the requested input and lists the available full template forms, including integer parameters.

References: Wrapping/…/template_class.py• L47-102 Wrapping/…/template_class.py• L442-558 Wrapping/…/base.py• L45-119 Wrapping/…/helpers.py• L19-227 Wrapping/…/extras.py• L2535-2586 Wrapping/…/igenerator.py• L1144-1288

Reader type inference

Image reader construction uses file metadata to select a wrapped image component type, pixel form, and dimension. This lets itk.imread create a typed reader without requiring the caller to name the full image type.

The reader accepts known component and pixel descriptions that exist in the wrapping scope. If ImageIO reports an unknown component, it raises a KeyError that names the reported value and points the caller to pixel_type= or a typed reader. A fallback-only read does not hide this error when the file metadata cannot identify a supported component.

References: Wrapping/…/template_class.py• L129-203 Wrapping/…/test_imread_unknown_component_type.py• L19-68

Array and image conversion

The support layer exchanges image data with NumPy through explicit copy and shared-view contracts. It infers a wrapped image type from the NumPy dtype and shape when possible, and it requires an explicit type when the build does not include a matching template.

ITK image sizes use the reverse of the normal NumPy shape under the default axis contract. Non-C-contiguous inputs are normalized before conversion, so transposed and sliced arrays keep their own shape and pixel order. View conversion warns when this normalization requires a copy.

The runtime also maps wrapped image types to portable descriptors and maps those descriptors back to available ITK image or vector-image types. These descriptors preserve image dimension, component type, pixel form, and component count for clients that cannot use Python template objects directly.

References: Wrapping/…/extras.py• L268-486 Wrapping/…/helpers.py• L222-377 Wrapping/…/extras.py• L425-546 Wrapping/…/helpers.py• L21-66 Wrapping/…/pyBase.i• L746-896

Image library exchange

The support runtime exchanges images with VTK, SimpleITK, and xarray while carrying pixel data and image geometry across library boundaries. It uses named axis and spatial-order contracts instead of guessing when two libraries use different conventions.

The VTK helper records the source ITK dimension with the image data. This lets a round trip distinguish a padded 2D image from a real 3D image with one slice. The direct VtkGlue filter path provides a separate SWIG boundary for itk.Image and vtkImageData, so its native object checks and geometry behavior are validated independently of the NumPy helper path.

SimpleITK conversion reads explicit XYZ geometry keys when available and otherwise uses its accessors. Conversion back to SimpleITK rejects an ITK image whose buffered region differs from its largest possible region because SimpleITK cannot represent two extents. xarray conversion uses named dimensions and coordinates, and an explicit view keeps a lifetime link to the source image.

The xarray contract accepts only x, y, z, t, and optional c dimensions. It reverses spatial dimensions to match ITK order, preserves origin and spacing from coordinate values, and uses a spacing of 1.0 for a singleton axis. It rejects unknown dimensions and reorders non-canonical input dimensions before creating an image. A round trip preserves the image name, direction, metadata, data, and supported geometry.

References: Wrapping/…/extras.py• L688-801 Wrapping/…/extras.py• L804-872 Wrapping/…/extras.py• L875-935 Wrapping/…/xarray.py• L37-151 Modules/…/VtkGlueRoundTripTest.py• L19-111 Wrapping/…/extras.py• L736-808 Wrapping/…/test_xarray.py• L30-207

Lazy imports

Lazy imports delay native module loading until code asks for a class or function. This keeps import itk light while preserving a flat package namespace and named per-module namespaces for discovery, interactive use, and serialization.

Attribute ownership

At package initialization, the runtime reads generated module configuration and builds an ownership map from each advertised Python name to the module that provides it. Attribute access then loads that module and its dependencies, copies the resulting symbols into the requested namespace, and caches them.

The same delayed names are available through synthetic namespaces such as itk.ITKCommon. A name with more than one possible owner follows the generated ownership order, with the module that defines the class taking precedence over a fallback owner.

References: Wrapping/…/__init__.py• L135-227 Wrapping/…/_lazy_submodule.py• L40-107 Wrapping/…/base.py• L393-449

Load safety and eager mode

Each SWIG module uses a recursive lock for its first load. This makes a module and its dependency loads one safe action for the loading thread, while different modules can load in parallel.

Lazy loading is the default. ITK_EAGER_IMPORT and force_load() provide an eager mode for applications that need native import errors at package start rather than at first use. Lazy module objects also register under their import names so pickle and worker systems can resolve them.

References: Wrapping/…/__init__.py• L72-125 Wrapping/…/__init__.py• L230-259 Wrapping/…/_lazy_submodule.py• L109-124 Wrapping/…/extras.py• L19-47 Wrapping/…/CMakeLists.txt• L263-271

Binding validation

Binding validation checks that the Python surface matches the intended C++ surface and the support runtime's contracts. It covers declaration coverage, template and process behavior, lazy loading, array ownership, library exchange, callback behavior, and import cost.

Coverage checks

Coverage tools compare class names found in ITK headers with names visible through Python. They report missing classes by API family and allow deliberate exclusions to remain explicit. Returned-type coverage also finds C++ types that normal wrapped methods return but the Python surface does not expose.

Coverage is registered by API family in the Python test group. Some families run only with the default module set, and filter coverage can use an explicit exclusion list while the remaining checks require full visibility. The TransformInsightLegacy wrapping test group also registers a Python check for BSpline transform spline-order exposure.

References: Wrapping/…/wrappingCoverage.py• L49-100 Wrapping/…/returnedTypeCoverage.py• L163-220 Wrapping/…/CMakeLists.txt• L1-61 Modules/…/CMakeLists.txt• L1-8

API consistency checks

Consistency checks load the wrapped set and verify the conventions used by Python callers. They protect template selection, process outputs, C type aliases, native array arguments, lazy first loads, GIL behavior, and the copy-versus-view rules for image data.

The support tests also check Python filter callbacks. PyImageFilter must run Python-defined pipeline hooks, update output regions, expose a functional interface, and propagate callback errors through the Python call that updates the pipeline.

The optional-import check forces xarray, PyTorch, and SimpleITK imports to fail after package metadata reports them as installed. It verifies that array and ITK image inputs still use the core conversion path. The template-error check verifies that a bad selection gives a useful list of complete wrapped choices and a clear description of the received value.

The GIL checks verify that Update() and UpdateLargestPossibleRegion() can release Python's global interpreter lock when enabled. The safety checks cover callbacks, concurrent callbacks, exception return, object destruction, independent image work, signal delivery, deadlock risk, and repeated threaded create-and-destroy cycles.

The broad support test also checks package callbacks, full loading, image and mesh IO, serialization, pipeline calls, and common data conversions. It checks VTK helper round trips for pixels, geometry, component counts, and source dimensions. Dedicated VtkGlue tests also check direct filter round trips and reject non-VTK objects before native pointer use. The helper test checks conversion between wrapped image types and portable type descriptors. The xarray test checks named dimensions, coordinate-based geometry, metadata, round trips, and optional four-dimensional data. The stub merge test protects the inheritance order used by generated type hints.

Image-read validation also checks that an unrecognized ImageIO component produces a clear error and that fallback_only=True does not turn unsupported file metadata into a successful read. The test is registered only when the default modules and the float image type are available.

References: Wrapping/…/verifyTTypeAPIConsistency.py• L19-93 Wrapping/…/verifyGetOutputAPIConsistency.py• L19-118 Wrapping/…/PyImageFilterTest.py• L19-132 Wrapping/…/test_gil_release.py• L9-82 Wrapping/…/test_gil_release_safety.py• L109-498 Wrapping/…/extras.py• L19-241 Wrapping/…/extras.py• L736-808 Modules/…/VtkGlueABI3EncodingTest.py• L19-101 Modules/…/VtkGlueRoundTripTest.py• L19-111 Wrapping/…/helpers.py• L18-66 Wrapping/…/test_xarray.py• L19-210 Wrapping/…/pyi_generator_merge_test.py• L29-43 Wrapping/…/test_imread_unknown_component_type.py• L19-68 Wrapping/…/test_optional_import_failure.py• L19-69 Wrapping/…/test_template_type_error.py• L19-40 Wrapping/…/CMakeLists.txt• L63-118 Wrapping/…/CMakeLists.txt• L203-257 Wrapping/…/CMakeLists.txt• L290-317

The wider bridge model is described in Language and library bridges. The build and package path is described in Module build and distribution. The validation system is described in Testing and continuous integration, and wrapper registration connects to Registration workflows.

Change checklist

When these files or sections are changed, remember to consider these:

  • A .wrap rule or supported type set changes CastXML discovery, SWIG aliases, module configuration, and generated type hints.
  • A dimension or scalar-type guard in a module wrapper must keep the resulting template names aligned with the C++ class signature and the package's supported type registry.
  • A shared type registry change must keep generated C++ names, SWIG names, module names, and dependent wrapper variants aligned.
  • A template family used as a template argument must remain a distinct runtime key so its dependent variants do not collide.
  • A CastXML source, version, or host-selection change must keep the executable contract aligned with the wrapper probe and supported build hosts.
  • A BSpline order or dimension change must keep the transform family, initializer, interpolation weights, dependent FunctionBase types, and default selection aligned.
  • A module submodule order or wrapper rename must stay aligned with generated interface names, index files, and Python template ownership.
  • A module dependency change must stay aligned across index data, generated configuration, and recursive Python loading.
  • A module-specific import preamble must remain safe for the platform loader and run before dependent native packages import.
  • A Python package or stub install destination change must preserve normalized paths for source installs and wheel layouts.
  • A documentation wrapping change must keep module and dependency include paths aligned with header discovery and generated docstring interfaces.
  • A change to SWIG proxy behavior must preserve native ownership, exception translation, and the Python protocols added by the common support rules.
  • A change to image conversion must preserve axis order, copy versus view ownership, and the lifetime of shared buffers.
  • A change to VTK exchange must preserve source dimension metadata, geometry, component mapping, and the direct typemap checks.
  • A change to process-object generation must keep input conversion, snake-case keyword names, output type hints, and template selection aligned.
  • A change to optional array-library detection must preserve the fallback path when package metadata exists but importing the package fails.
  • A change to template selection errors must keep the displayed full choices and the received input form aligned with the wrapped template keys.
  • A change to image-reader metadata mapping must preserve the distinction between a known wrapped component and an unknown ImageIO report, including the error path for fallback_only reads.
  • A change to SimpleITK or xarray exchange must preserve explicit geometry and axis contracts rather than falling back to ambiguous names.
  • A change to portable image type descriptors must keep scalar widths, pixel forms, vector component counts, and available wrapped template names reversible.
  • A change to generated stub merging must preserve class metadata checks and stable base-class order.
  • A change to GIL release or Python callback paths must preserve lock reacquisition, exception return, object lifetime, and concurrent use contracts.
  • A new validation test must be added to the matching CMake test group so the contract runs in the build.

Important failure modes

TriggerConsequenceGuard
CastXML uses a different build context from the C++ wrapper targetSWIG sees missing or unusable declarationsGenerate discovery inputs from the wrapper target's compiler and include settings
The system CastXML executable is missing or below the supported minimumConfiguration stops before wrapper generationUse a supported CastXML installation or let ITK provide its tool build
A supported host selects an invalid or unverified CastXML packageType discovery cannot start or uses an unexpected toolKeep host selection tied to verified downloads and hashes
The shared type registry omits a type variant required by a dependent wrapperPython cannot select a needed template or a dependent interface cannot resolve its aliasKeep shared type choices and dependent .wrap rules aligned, then run coverage checks
A wrapper's dimension or scalar-type guard excludes a needed C++ variantThe class or template is absent from Python for that buildCompare wrapper conditions with the class signature and run API coverage checks
A supported template family is treated as an ordinary object or dropped from a template keyDistinct dependent variants collide and one Python choice becomes unreachableResolve registered template families as template arguments and preserve them in lookup keys
A required type is absent from the wrapping scopePython cannot select the C++ typeRun header and returned-type coverage checks
A required BSpline order or dependent weight type is absentA transform or initializer template is unavailable at first useKeep the order, dimension, and dependent .wrap rules aligned and run the spline-order check
A dependent module has stale index or configuration dataAlias resolution or first-use loading failsGenerate index, configuration, and native targets from one wrapping pass
A module submodule order or wrapper name does not match generated outputsA module interface or Python owner is missingKeep .wrap names, submodule order, and generated index inputs aligned
A Python install destination is not normalized before installationCMake emits path-policy warnings or places package artifacts inconsistently in wheel buildsNormalize the site-package destination for package files and generated stubs
A module's target include paths are not used for documentation discoveryDoxygen receives no wrapped headers and generated docstrings are emptySearch the module and dependency include paths when locating wrapped headers
A required VTK DLL directory is not registered on WindowsVTK import fails before a VtkGlue bridge can loadRegister the VTK directory in the generated module configuration before VTK import
Optional package metadata says a package is installed but its import raises an exceptionProcess helpers can fail during use instead of falling back to core array or ITK behaviorTreat failed optional imports as unavailable and keep the core conversion path active
A caller selects an unsupported template or passes a non-tuple template keyThe error does not show how to choose a valid wrapped typeReport the received input and every available full template instantiation
VTK changes its __this__ or Addr=0x... object encodingDirect pointer exchange cannot rebuild a VTK objectRun the ABI3 encoding canary against supported VTK versions
A non-VTK object with a forged native pointer reaches the input typemapThe process can accept invalid data or crash in native codeRequire an actual vtkImageData instance before pointer conversion
A non-C-contiguous array is treated as a direct viewShape or pixel order can be wrongNormalize the layout and test copy, view, transpose, and slice cases
A shared image view does not retain its sourceA later Python read can access released memoryKeep the source alive through the exported buffer or array
ImageIO reports an unknown component typeAutomatic reader selection fails without naming the reported typeRaise the component value in KeyError and direct callers to pixel_type= or a typed reader
fallback_only=True retries a file whose component type is unknownThe read still cannot produce a valid typed imageKeep the failure explicit rather than selecting an unsupported fallback
SimpleITK receives an image with two different extentsGeometry or pixel extent cannot be representedReject mismatched buffered and largest regions before conversion
An xarray input uses an unknown dimension or a singleton axis gets a data-step spacingConversion fails or assigns false geometryValidate dimension names and use unit spacing when an axis has one sample
A wrapped foreign type passes a broad sequence checkSWIG selects the wrong overloadReject unrelated SWIG objects before sequence conversion
Generated class records disagree or reorder basesType hints describe an invalid class hierarchyReject conflicting metadata and preserve first-seen base order
A borrowed native callback reference is returned without ownershipPython can access a released callback objectReturn an owned reference at the SWIG boundary
A GIL-release path calls Python without reacquiring the GILA callback can crash or deadlock and native exceptions can be lostKeep callback reacquisition and thread-state restoration covered by the GIL safety tests
A Python filter callback raises but the native update hides the errorA pipeline can report success with invalid outputPreserve callback exception propagation and run PyImageFilterTest

Key files

FileWhy to read it
Wrapping/ConfigureWrapping.cmakeDefines shared wrapping inputs and build choices.
Wrapping/WrapITKTypes.cmakeDefines shared template names and the type variants required by wrapped classes.
Wrapping/…/CMakeLists.txtDefines the CastXML tool source, version checks, host packages, and build path used for type discovery.
Wrapping/macro_files/itk_auto_load_submodules.cmakeShows how wrapper rules become discovery probes and interface inputs.
Wrapping/macro_files/itk_end_wrap_module.cmakeShows how module interfaces, indexes, configuration, and native Python targets are assembled.
Wrapping/…/igenerator.pyDefines declaration conversion, aliases, process functions, and type information.
Wrapping/…/doxy2swig.pyDefines the general Doxygen-to-SWIG documentation conversion.
Wrapping/…/itk_doxy2swig.pyAdapts documentation names and configured inputs to generated ITK SWIG interfaces.
Wrapping/…/CMakeLists.txtDefines the Python package layout, SWIG invocation, installation paths, and native module assembly.
Wrapping/TypedefMacros.cmakeDefines wrapper type discovery inputs and module-aware header lookup for documentation.
Modules/Core/Transform/wrapping/itkBSplineTransform.wrapIllustrates dimension and spline-order selection for a public transform family.
Modules/Core/Transform/wrapping/itkBSplineTransformInitializer.wrapIllustrates dependent transform and image template selection.
Modules/Filtering/Cuberille/wrapping/itkCuberilleImageToMeshFilter.wrapIllustrates a wrapper that limits a filter to supported 3D scalar image-to-mesh variants.
Modules/Filtering/Strain/wrapping/itkTransformToStrainFilter.wrapIllustrates dimension-wide wrapping with explicit transform and scalar type choices.
Wrapping/Generators/Python/PyBase/pyBase.iDefines common native object behavior and Python buffer contracts.
Wrapping/…/base.pyDefines dependency-aware native loading and template registration.
Wrapping/…/template_class.pyDefines template lookup, template-family arguments, automatic type selection, and reader type inference.
Wrapping/…/extras.pyDefines array, image, geometry, serialization, and library exchange helpers.
Wrapping/Generators/Python/itk/support/ModuleConfig.py.inDefines the per-module runtime data used for dependencies, templates, factories, and import setup.
Wrapping/…/helpers.pyDefines optional array-library support and portable image type mappings.
Wrapping/…/xarray.pyDefines the xarray image and geometry exchange contract.
Wrapping/…/__init__.pyDefines package ownership and lazy name resolution.
Wrapping/…/pyi_generator.pyDefines generated Python type-hint assembly.
Modules/…/CMakeLists.txtShows the VTK platform import setup for the wrapped module.
Wrapping/…/CMakeLists.txtShows how coverage, runtime, lazy-load, conversion, GIL, reader, and stub checks enter validation.
Wrapping/…/test_optional_import_failure.pyChecks fallback behavior when optional packages are installed but cannot be imported.
Wrapping/…/test_template_type_error.pyChecks useful diagnostics for invalid template selections.
Modules/…/VtkGlueRoundTripTest.pyValidates direct ITK-to-VTK-to-ITK filter exchange and input safety.
Modules/…/VtkGlueABI3EncodingTest.pyProtects the VTK object encodings used by the limited-API bridge.
Wrapping/…/test_imread_unknown_component_type.pyValidates clear failure when image metadata reports an unsupported component type.
Wrapping/…/PyImageFilterTest.pyValidates Python callbacks and error propagation in a wrapped image filter.
Wrapping/…/test_gil_release_safety.pyValidates callback, exception, lifetime, signal, and concurrency safety across the GIL boundary.
Wrapping/…/extras.pyProvides the broad support, array ownership, and VTK exchange smoke test.
Wrapping/…/helpers.pyChecks portable image type conversion for scalar, fixed-component, and variable-component images.
Wrapping/…/test_xarray.pyChecks xarray data, axis, geometry, metadata, and round-trip behavior.
Wrapping/…/pyi_generator_merge_test.pyProtects stable base-class order in generated stubs.
Modules/…/CMakeLists.txtRegisters the Python test for BSpline transform spline-order exposure.